0

I made 2 classes: Input which implements read method, and Output which implements write method

I am trying to call a shell command and capture the input and output. This is my code:

import subprocess
command = "date"
output = Output()
input = Input()
process = subprocess.Popen(command,
                           stdout=output, stdin=input, shell=False)

but when I check the output instance it says that it contains no data.

1 Answer 1

2

Technically, those class instances are probably invalid parameters, unless they inherit from a file object.

According to the documentation (emphasis mine):

stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively. Valid values are PIPE, DEVNULL, an existing file descriptor (a positive integer), an existing file object, and None. PIPE indicates that a new pipe to the child should be created. DEVNULL indicates that the special file os.devnull will be used. With the default settings of None, no redirection will occur; the child’s file handles will be inherited from the parent. Additionally, stderr can be STDOUT, which indicates that the stderr data from the applications should be captured into the same file handle as for stdout.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way to make it work without using subprocess? By the way the main point of this is so that I can use a tkinter window for the user interface.
Just use PIPE. Then you should be able to just use process.stdout.read() and process.stdin.write(). But keep in mind that the operating system's buffers are not infinite.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.