M
M
Macbet2014-01-19 23:01:35
Python
Macbet, 2014-01-19 23:01:35

Executing a Compiled Program in a Python Script

There is a ready-made console program so that during the execution of the pyhton script, commands with keys are passed to it and its validity is monitored, is it possible to do this in python?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2014-01-19
@Macbet

Here are the code snippets from my Python 3.3 script:

def _run_process(self, args):
    proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdoutBin = proc.stdout.read()
    stderrBin = proc.stderr.read()
    proc.stdout.close()
    proc.stderr.close()
    proc.wait()
    self._toolResult['retcode'] = proc.returncode
    self._toolResult['stdout'] = stdoutBin.decode('ascii')
    self._toolResult['stderr'] = stderrBin.decode('ascii')

Y
Yuri Shikanov, 2014-01-19
@dizballanze

Maybe. See subprocess module .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question