0

I'm trying to execute the following shell command in Python:

echo abc && echo -ne \\x00 > file && echo efg

I tried doing it by calling os.system but it seems to ignore the -ne flag of echo.

What can I do to run it properly?

import os
os.system('echo abc && echo -ne \\x00 > file && echo efg')
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
Infinity
  • 41
  • 4
  • Check out the `subprocess` module: https://docs.python.org/2/library/subprocess.html – TeaPow Oct 24 '17 at 10:44
  • Possible duplicate of [Running shell command from Python and capturing the output](https://stackoverflow.com/questions/4760215/running-shell-command-from-python-and-capturing-the-output) – ilim Oct 24 '17 at 10:45
  • 1
    os.system probably execute the command from the "sh" shell, but echo is a built-in command so different shells have different ways to interpret it. Make sur the -ne flag is available on sh and not only on bash or zsh ! – Orionss Oct 24 '17 at 10:52
  • Adding to @Orionss comment, replacing, it does use `sh`, which doesn't have `-ne` as options for the built-in echo, you can replace it with `/bin/echo`, which *should* accomplish the same thing. – Anya Shenanigans Oct 24 '17 at 11:21
  • the solution that says to replace echo with /bin/echo worked for me, ty – Infinity Oct 24 '17 at 16:15

0 Answers0