This commit is contained in:
2024-11-29 18:15:30 +00:00
parent 40aade2d8e
commit bc9415586e
5298 changed files with 1938676 additions and 80 deletions

View File

@ -0,0 +1,27 @@
import sys
from easyprocess import EasyProcess
python = sys.executable
print("-- Run program, wait for it to complete, get stdout:")
s = EasyProcess([python, "-c", "print(3)"]).call().stdout
print(s)
print("-- Run program, wait for it to complete, get stderr:")
s = EasyProcess([python, "-c", "import sys;sys.stderr.write('4\\n')"]).call().stderr
print(s)
print("-- Run program, wait for it to complete, get return code:")
s = EasyProcess([python, "--version"]).call().return_code
print(s)
print("-- Run program, wait 1.5 second, stop it, get stdout:")
prog = """
import time
for i in range(10):
print(i, flush=True)
time.sleep(1)
"""
s = EasyProcess([python, "-c", prog]).start().sleep(1.5).stop().stdout
print(s)

View File

@ -0,0 +1,5 @@
from easyprocess import EasyProcess
cmd = ["echo", "hello"]
s = EasyProcess(cmd).call().stdout
print(s)

View File

@ -0,0 +1,12 @@
import logging
import sys
from easyprocess import EasyProcess
python = sys.executable
# turn on logging
logging.basicConfig(level=logging.DEBUG)
EasyProcess([python, "--version"]).call()
EasyProcess(["ping", "localhost"]).start().sleep(1).stop()

View File

@ -0,0 +1,24 @@
import sys
from easyprocess import EasyProcess
python = sys.executable
prog = """
import time
for i in range(3):
print(i, flush=True)
time.sleep(1)
"""
print("-- no timeout")
stdout = EasyProcess([python, "-c", prog]).call().stdout
print(stdout)
print("-- timeout=1.5s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=1.5).stdout
print(stdout)
print("-- timeout=50s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=50).stdout
print(stdout)

View File

@ -0,0 +1,7 @@
import sys
from easyprocess import EasyProcess
python = sys.executable
v = EasyProcess([python, "--version"]).call().stderr
print("your python version:%s" % v)

View File

@ -0,0 +1,18 @@
import os
import sys
import urllib.request
from os.path import abspath, dirname
from time import sleep
from easyprocess import EasyProcess
webserver_code = """
from http.server import HTTPServer, CGIHTTPRequestHandler
srv = HTTPServer(server_address=("", 8080), RequestHandlerClass=CGIHTTPRequestHandler)
srv.serve_forever()
"""
os.chdir(dirname(abspath(__file__)))
with EasyProcess([sys.executable, "-c", webserver_code]):
sleep(2) # wait for server
html = urllib.request.urlopen("http://localhost:8080").read().decode("utf-8")
print(html)