Continuous shell process


Keywords
shell, bash, subprocess, sh
License
Other
Install
pip install shell-proc==3.0.9

Documentation

Shell Proc

Install

3.0.0 Changes

Major changes! Too many differences between linux, windows cmd, and windows powershell.

  • I separated everything into separate classes.
    • Shell is the default for the OS.
    • Can specify BashShell (LinuxShell), WindowsPowerShell, and WindowsCmdShell.
  • Changed parallel function in an attempt to use background processes.
    • Removed ParallelShell class
  • Added Command.raw_stdout and Command.raw_stderr.
  • Added Shell.is_windows_cmd and Shell.is_powershell.
  • Each shell has specific quote escape functions.
    • This can be a giant pain and could be improved with regex
  • Added show_all_output and show_commands for how the output is displayed.
  • Added extra and end arguments to the run function to add more control to the commands.

2.0.0 Changes

This library has recently been updated to support commands with stdin prompts. I noticed git and ssh would occasionally request pompt input from the user for authorization. The old approach would get the exit code by sending an echo to stdin. This would give the echo command as a user prompt. To support this a lot of things had to change. Windows users will notice some changes.

  • I changed how the echo results works and am using ";" instead of a second command passed into stdin.
  • I also changed the pipes to non-blocking allowing input prompts to be read.
    • Before the pipe reading waited on a newline.
  • Unfortunately, ";" did not really work with windows cmd.
    • Windows operations were changed to use powershell.
    • Powershell $? gives "True" or "False", so it does not give a proper exit_code.
    • Old cmd is still supported if you pass use_old_cmd=True into the Shell. Not guaranteed to work.
  • Added input which will only pass values into stdin without expecting a command to finish.

Run

Run a series of commands with results.

Run a series of terminal commands.

Run without blocking every command

Manually call commands and check results.

io.StringIO() Help

Below are several functions to read data from stdout and io.StringIO()

Run Python

Added support to call python in a subprocess

Run Parallel

Added support to run parallel subprocesses

Use Pipe

The pipe operator can be used with Command objects to take a completed command stdout and submit the text into a new commands stdin.

Input Prompts

As of version 2.0.0, Shell can work with input prompts. I noticed git and ssh would occasionally request pompt input from the user for authorization. I wanted to support this use case.

Input prompt code

Shell code

Output. Note, "Jane Doe" was entered in as input.

Give user input when prompted
Greetings!
Hello, who am I talking to? Jane Doe
It's nice to meet you 'Jane Doe'
Greetings!
Hello, who am I talking to? It's nice to meet you 'John Doe'
Exited successfully!