Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stdout_output = open('testfile.txt','w')
- process = subprocess.Popen(command,stdout=stdout_output,shell=True)
- stdout_read = open('testfile.txt','r')
- data = stdout_read.read()
- print data
- stdout_output = open('testfile.txt','w')
- process = subprocess.Popen(command,stdout=stdout_output,shell=True)
- time.sleep(3)
- stdout_read = open('testfile.txt','r')
- data = stdout_read.read()
- print data
- data = subprocess.check_output(command, shell=True)
- print data
- def do_stuff(proc, filename):
- # proc.poll() check if proc has ended
- while proc.poll() is None:
- print('Here you do whatever you want while you wait for the process')
- # do other stuff
- ping_pong.play()
- # here we are sure the command terminate and wrote his output
- proc.stdout.close()
- with open(filename) as f:
- return f.read()
- stdout_file = open('some_file', 'w')
- process = Popen(['command'], stdout=stdout_file)
- output = do_stuff(process, 'some_file')
- def reader(fd, finished):
- while not finished.is_set():
- data = fd.read()
- if data: print(data)
- time.sleep(SOME_TIMEOUT)
- process = subprocess.Popen(command,stdout=stdout_output,shell=True)
- finished = threading.Event()
- reader_thread = threading.Thread(target=reader, args=(stdout_output, finished))
- reader_thread.start()
- process.wait()
- finished.set()
- reader_thread.join()
- stdout_output = open('testfile.txt','w', 0)
- import subprocess
- """
- notifier.sh
- ------------------
- echo "This is me"
- sleep 4
- echo "This is me again"
- ------------------
- """
- command = ['bash', 'notifier.sh']
- process = subprocess.Popen(command, stdout=subprocess.PIPE)
- while True:
- data = process.stdout.readline()
- print data
- if 'This is me again' in data:
- break
Add Comment
Please, Sign In to add comment