Home > Blockchain >  collect subprocess outputs and write to excel in python
collect subprocess outputs and write to excel in python

Time:06-28

I wrote a loop in python to cope with a list of tasks, and during every loop certain outputs (plain text) from either stderr or stdout will be generated, what I want is trying to collect them inside python and at the end write them together into excel. I also tried before write them respectively after every loop into excel (through pandas) but it takes too long to run through all tasks as I suppose every export has to overwrite what already in excel. I would like to ask if there is suitable packages to cope with text in python in this regards.

Many thanks in advance.

CodePudding user response:

First, when you call subprocess run capture_output=True to the arguments like this:

subprocess.run(["ls", "-l", "/dev/null"], capture_output=True)

Second, depending on your data, you'll need to 'parse' the output using str split or NumPy.

And for the excel part, try using this guide.

Good Luck

  • Related