0

I want to write a python script that pipes a value of a variable (e.g. var = 5) into an external program. I want to store that output then in a .txt file. Since I want to run a couple of these processes simultaneously I tried to do this using subprocess. But I failed. Can someone help me?

Thanks a lot!

DerWzwo3
  • 9
  • 2
  • 1
    Edit your post and add the code ... – ROMANIA_engineer Jan 31 '16 at 20:00
  • [Possible duplicate](http://stackoverflow.com/questions/4514751/pipe-subprocess-standard-output-to-a-variable?rq=1) – Anmol Singh Jaggi Feb 01 '16 at 12:23
  • Something like this? `from subprocess import check_output # ls command out = check_output(["ls", "-als"]) # open the empty file logfilewriteout = open("/Users/youruser/Desktop/test.txt", 'w') logfilewriteout.write(out) logfilewriteout.close()` – adamteale Feb 01 '16 at 12:44
  • I see several questions here: 1. How to pass `var`'s value to a subprocess (too broad: how do you want to pass it: as a command-line parameter `Popen(['command', str(var)], ...)`, or via subprocess' stdin e.g., as `var`'s text ascii representation `print(var, file=process.stdin)`, or using some other [IPC method](https://goo.gl/Ggw2PH)?) 2. How to [redirect subprocess' stdout to a file](http://stackoverflow.com/q/9347004/4279) 3. How to [run multiple subprocesses in parallel](http://stackoverflow.com/q/14533458/4279). Please, limit your question to one issue per question. – jfs Feb 01 '16 at 20:31

0 Answers0