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?
Asked
Active
Viewed 868 times
-1
-
What's wrong with using `sys.stdin` / `sys.stdout` and your OS input/output redirections ? – bruno desthuilliers Apr 07 '15 at 12:02
-
I really dont know how to use it :P, can you please provide me the link to some good reference material, if possible? – Maulik Upadhyay Apr 07 '15 at 15:10
-
1`sys.stdin` and `sys.stdout` are 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 ? – bruno desthuilliers Apr 07 '15 at 15:45
-
Sorry for bothering you but I solved it thanks for your comment :) – Maulik Upadhyay Apr 07 '15 at 16:10
-
Downgrade because OP didn't seem to do any footwork (see @bruno's comment) and obviously is not familiar with http://www.catb.org/~esr/faqs/smart-questions.html. – boardrider Apr 08 '15 at 10:46
1 Answers
0
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.

Rod
- 754
- 11
- 21
-
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". – Maulik Upadhyay Apr 07 '15 at 15:09
-
you can use [subprocess](https://docs.python.org/2/library/subprocess.html) on script2 to execute (and get a return value) from script1 [example](http://stackoverflow.com/questions/6086047/get-output-of-python-script-from-within-python-script) – Rod Apr 07 '15 at 15:35
-
thanks I was just missing the "import" statement (link provided by you gave me this clue), thank you very much again :) – Maulik Upadhyay Apr 07 '15 at 16:13