For the first time, I ask for a little help, since I'm more of a ServerFault person.
I am writing scripts in Python and still love this language, but I have this little problem that makes my script not work.
Here is the line of code in question:
subprocess.call('xen-create-image --hostname '+nom+' --memory '+memory+' --partitions=/root/scripts/part.tmp --ip '+ip+' --netmask '+netmask+' --gateway '+gateway+' --passwd',shell=True)
I tried the same with os.popen. All variables are set correctly.
When I execute this command in my regular Linux shell, it works fine, but when I run it using my Python scripts, I get strange errors. I even replaced subprocess.call () with a print function to make sure I use the exact output of the command.
I looked at the environment variables of my shell, but they are almost the same ... I will send the error that I get, but I'm not sure if this is relevant to my problem.
Using the uninitialized value of $ lines [0] in the substitution (s ///) in / usr / share / perl 5 / Config / IniFiles.pm line 614. Using the uninitialized value of $ _ according to the pattern (m //) on the page / usr / share / perl 5 / Config / IniFiles.pm line 628.
I am not a Python expert, so most likely something is missing here.
Thank you in advance for your help,
Antoine
EDIT
Following miax's advice, I stopped using shell = True. Instead, I looked at the Python documentation for subprocess and used the following code snippet:
cmd = 'xen-create-image --hostname '+nom+' --memory '+memory+' --partitions=/root/scripts/part.tmp --ip '+ip+' --netmask '+netmask+' --gateway '+gateway+' --passwd' args = shlex.split(cmd) subprocess.call(args)
Unfortunately, this does not change anything ...
EDIT2
I used the hint given by miax, but I still get the above error ... Here is the code I used.
cmd = ['xen-create-image', '--hostname', nom, '--memory', memory, '--partitions=/root/scripts/part.tmp', '--ip', ip, '--netmask', netmask, '--gateway', gateway, '--passwd'] subprocess.call(cmd)
This is really weird ... The exact command works fine when I run it in a regular shell ...