I wrote a python script for file manipulations, Since I don't know the way to redirect output file from one python script as input file in another python script, I have to run both the scripts separately. I want to learn as to how to pass on the output file from one script as input file for another script. Can someone please guide me regarding this query?
1 Answer
Well, I'm not sure if I understood correctly...
You can call the second script from your first like this :
os.system("script2.py "+name_of_the_file)
since this is inside the first script, you can just store the output path and pass as parameter to the second script.
I'm using os.system to execute a shell simulating the manual call to the second script.
3 Comments
Maulik Upadhyay
Thanks for the response, let me elaborate my query: I have written two scripts (script1, script2), first script ("script1") takes an input file ("file1") and after processing outputs another file ("file2"), second script ("script2") takes "fiile2" as input file and after several modifications outputs "file3" and "file4". Now, I want to connect two scripts so that I only need to run "script2" in order to get "file3" and "file4".
Rod
you can use subprocess on script2 to execute (and get a return value) from script1 example
Maulik Upadhyay
thanks I was just missing the "import" statement (link provided by you gave me this clue), thank you very much again :)
sys.stdin/sys.stdoutand your OS input/output redirections ?sys.stdinandsys.stdoutare documented in Python's doc, and you didn't evn bothered to tell which OS you're using - but chances are it's also fully documented. What about doing your homework first then come back with more specific questions ?