Skip to content

yingjiaxin/easysh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easysh

an easy to execute shell in python

Requirements

Python 3.3 +

Installation

pip install easysh

Usage

from easysh import Shell

output= Shell.exec('ls -l')
print(output)

asyncio

from easysh import Shell

output= await Shell.aexec('ls -l',cwd='/var')
print(output)

Real-time output

from easysh import Shell

with Shell.create('ls -l') as std:
    for line in std:
        print(line)

asyncio Real-time output

from easysh import Shell

async with Shell.create('ls -l') as std:
    async for line in std:
        print(line)

execute shell command with timeout

from easysh import Shell
from subprocess import TimeoutExpired

try:
    await Shell.aexec('python', timeout=3)
except TimeoutExpired as e:
    print(e)

handling error

from easysh import Shell, ShellError

try:
    Shell.exec("unknown command")
except ShellError as e:
    print(e)

capturing the output and error streams

from easysh import Shell

# capturing the output and error streams
with Shell.create("unknown command", raise_on_stderr=False) as std:
    output = std.read()
    print(output)
    print(std.has_errors)

About

an easy to execute shell in python

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages