简体   繁体   中英

How to pass a string with special chars in python to os.system. (E.g. python test.py |& tee output.txt)

The command will fail as a result of char "&". Eg python test.py |& tee output.txt

On my system, using |& gives me this error message

sh: -c: line 0: syntax error near unexpected token `&'

|& is not a syntax supported by sh , but it is supported by bash . This isn't an issue with "special characters", but rather an issue with the syntax supported by the shell that os.system() runs. If this is the error you're getting, you could use this sh -compatible syntax instead

os.system("python test.py 2>&1 | tee output.txt")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM