Jonathan Jonathan - 6 months ago 9
Perl Question

How to invoke perl script that need args from python

i'm new to python...
i'm writing my script in python and i want to invoke perl script from it

this is the line i want to call

perl conv_intel_hex_2_verilog.pl arg1 arg2


while arg1 is the input from the python script and arg2 is new file that
i'm creating

so far i have this

def main(argv):
file = open("test.hex","w")
input = argv[0];
subprocess.call(["perl", "conv_intel_hex_2_verilog.pl", input]);
file.close();


this run and do nothing

and when i'm changing the

subprocess.call(["perl", "conv_intel_hex_2_verilog.pl", input]);


to

subprocess.call(["perl", "conv_intel_hex_2_verilog.pl", input ,file]);


it doesnt compile...

I'm sure its a very novice question....

Answer

As you've described it, the program you're running expects its second argument to be the name of a file, so that's what you need to give it. In your current code, you're giving it a Python file object, which is not the same as the string name of a file.

subprocess.call(["perl", "conv_intel_hex_2_verilog.pl", input, "test.hex"]);

There is no need to create the file object prior to running that code, either. The other program will surely create it for you, and might even balk if it finds that the file already exists.