1

This question and answer demonstrates how to use Python's subprocess module to interact with bash from Python.

So if subprocess doesn't use the system's default shell, then what shell does it use to run commands like this:

    import subprocess

    print subprocess.check_output(["ls", "-la"])
Sam Malayek
  • 3,595
  • 3
  • 30
  • 46

1 Answers1

2

If shell is not passed as a keyword argument it uses fork_exec, or _winapi.CreateProceess

If shell=True:

  • posix it uses /bin/sh, .
  • windows it uses cmd.exe.

See:

jmunsch
  • 22,771
  • 11
  • 93
  • 114
  • 1
    Since he doesn't use `shell=True`, this answer isn't really relevant. – Barmar Jan 04 '20 at 00:10
  • Right, thanks, I'm mainly curious about the software components between Python and the program that's executed if it's not a shell. I'm starting to realize that it must be C system calls. – Sam Malayek Jan 04 '20 at 00:10
  • @SamMalayek np. – jmunsch Jan 04 '20 at 00:25
  • @SamMalayek, ...I wouldn't really call them "C" system calls -- any C standard-library wrapper like `execlp` eventually goes to an actual syscall, like `execve`, you can invoke without the C library involved at all; hence programs written in languages like Go that don't use libc being able to start other programs. – Charles Duffy Jan 04 '20 at 00:37