i'm trying to get informations of a network interface on a linux machine with a python script, i.e. 'ifconfig -a eht0'. So i'm using the following code:
import subprocess proc = subprocess.Popen('ifconfig -a eth0', shell=True, stdout=subprocess.PIPE) proc.wait() output = proc.communicate()[0] Well if I execute the script from terminal with
python myScript.py or with
python myScript.py & it works fine, but when it is run from background (launched by crontab) without an active shell, i cannot get the output.
Any idea ?
Thanks
outputto see if it worked or not (whether in background or in active shell)? Do you save it to a file? If so, does the file get created but with no content or no file at all?shell=True, egproc = subprocess.Popen(['ifconfig', '-a', 'eth0'], stdout=subprocess.PIPE)?shell=Falsei get this errorOSError: [Errno 2] No such file or directoryshell=Trueyou must pass the command line as a list, as shown in my previous comment.[Errno 2] No such file or directory