Want a Python function can run shell command, such as,
echo 'Process started'; ping 127.0.0.1 -i 2 ; echo 'Process finished'
Requirements,
- It can capture real time output, and when command finished, it has a return value.
- It can set timeout, and when timeout, the command should be killed.
Can someone help me on this?
Subprocess.run looks not work, cause command is not killed, still running,
subprocess.run(cmd, stderr=sys.stderr, stdout=sys.stdout, shell=True, timeout=timeout)