import subprocess
import select
# batch file
batch_file_path = 'path/to/batch/file.bat'
process = subprocess.Popen(batch_file_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Monitor the status
while True:
# Wait for output
streams = select.select([process.stdout, process.stderr], [], [], 1.0)[0]
for stream in streams:
output = stream.readline()
if output:
print(output.strip().decode())
# Check if the process
if process.poll() is not None:
break
if process.returncode == 0:
# Your code to shutdown the Azure VM
pass
else:
# Your code to handle error
pass
1条答案
按热度按时间5lhxktic1#
是的,你可以通过python
subprocess
模块进行监控。您也可以check microsoft offical documentation of Batch job
您可以尝试此类型代码: