-1

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?

5
  • What's wrong with using sys.stdin / sys.stdout and your OS input/output redirections ? Commented Apr 7, 2015 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? Commented Apr 7, 2015 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 ? Commented Apr 7, 2015 at 15:45
  • Sorry for bothering you but I solved it thanks for your comment :) Commented Apr 7, 2015 at 16:10
  • Downgrade because OP didn't seem to do any footwork (see @bruno's comment) and obviously is not familiar with catb.org/~esr/faqs/smart-questions.html. Commented Apr 8, 2015 at 10:46

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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".
you can use subprocess on script2 to execute (and get a return value) from script1 example
thanks I was just missing the "import" statement (link provided by you gave me this clue), thank you very much again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.