Quantcast
Channel: How to redirect a command's output to file, when the command is via a wrapper's system call? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Answer by CHebs2018 for How to redirect a command's output to file, when the command is via a wrapper's system call?

$
0
0
import subprocess, sys, shlex

try:
    process = (subprocess.Popen(shlex.split(command), 
            stdout=subprocess.PIPE, 
            stderr=subprocess.PIPE, 
            shell=True, cwd="Pass desired directory in as string variable")

  stdout, stderr = process.communicate()

use the shlex to build your command, and subprocess to execute it in the command prompt.

subprocess.Popen Allows you to set the current working directory and set a pipe up for IPC.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>