0

I am trying to run some shell scripts from python, logging the stdout to a text file.

I tried to run the following dummy example. It works fine when I run the command from terminal, but writes an empty file when I call it from python.

Any idea why is that happening?


Shell Script: (~/shell_test)

echo "hello"

Command Call: (Works as expected from the terminal - shell_test_output.txt is created and "hello" is printed)

cd ~ && ./shell_test &>~/shell_test_output.txt

Python: (shell_test_output.txt is written as empty file)

os.system("cd ~ && ./shell_test &>~/shell_test_output.txt")
Deena
  • 5,925
  • 6
  • 34
  • 40
  • 1
    Possible duplicate of [Redirecting stdio from a command in os.system() in Python](http://stackoverflow.com/questions/3197509/redirecting-stdio-from-a-command-in-os-system-in-python) – Oleksandr Kravchuk Aug 10 '16 at 10:29
  • I try this. shell_test_output.txt is written as not empty. What is the return code of os.system("cd ~ && ./shell_test &>~/shell_test_output.txt") – Mustafa DOGRU Aug 10 '16 at 11:18

0 Answers0