logo
down
shadow

Difficulty using subprocess.check_output with command line argument in many parts


Difficulty using subprocess.check_output with command line argument in many parts

By : Gerard HAN
Date : November 20 2020, 11:01 PM
seems to work fine Split outstr and pass splitted string within list to check_call(). Easiest way for making change in your current code will be to make it as:
code :
from subprocess import check_call

outstr = "--+-+--+-----+--+++-+-+-- --+-++-+---+--+--++-++++- +--+---++++-+++-++-+-++++ --+-----+---+--++++---++- ----+----++++++-++++---+- ----------++-----++------ +--++-+-++++---+++--+++++ +-+-----++-+++-----+++-++ -++++--+-++--++---++-+++- +--++++-++----+---+--++-+ +++----+--++-+++-+--+++++ -++++-+-++++-+++------+++ -++-++-+--++--+---+-+---+ +-+++---+---++--+++--+--+ ++-+-+--++--+-------+-+-- ---++--+-+--+-+++-+++---- -+---+++-------+++-+----- +-+--------++++++--+-++-+ ++++-+++++++++-----+++++- -+++++-+---+-++---++++--- +-+---+++-+---+-++--++--- +-+-++-++++-+---------+-+ +-+++---++-----+-+--+--++ ++++++-+-++--+----++-+-+- ---+--++--------+++--+---"

check_call_args = ["/home/user/Dennis"] + outstr.split(' ')
check_call(check_call_args)


Share : facebook icon twitter icon
Variable inside subprocess.check_output argument ? [Python]

Variable inside subprocess.check_output argument ? [Python]


By : Sydney
Date : March 29 2020, 07:55 AM
Does that help simple question: , Did you mean to do this?
code :
print subprocess.check_output(["program",
                               "-v",
                               "-a5",
                               "-t%i" % test,
                               "-oURL",
                               "-uUSER",
                               "-pPASS"])
Python subprocess.check_output(args) fails, while args executed via Windows command line work OK

Python subprocess.check_output(args) fails, while args executed via Windows command line work OK


By : user3162220
Date : March 29 2020, 07:55 AM
With these it helps Some problems with python subprocess.check_output.
code :
output = subprocess.check_output(args,shell=True)
Using subprocess.check_output for a command with 2>/dev/null

Using subprocess.check_output for a command with 2>/dev/null


By : user3815863
Date : March 29 2020, 07:55 AM
With these it helps For 2>/dev/null, the appropriate way to control redirection of file descriptor 2 with the subprocess.Popen family of calls is stderr=:
code :
# Python 2.x, or 3.0-3.2
output = subprocess.check_output(['du', '-g', '-d1', '/Users'],
                                 stderr=open('/dev/null', 'w'))
# Python 3.3 or newer
output = subprocess.check_output(['du', '-g', '-d1', '/Users'], stderr=subprocess.DEVNULL)
p = subprocess.Popen(['du', '-g', '-d1', '/Users'],
                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
  raise Exception(stderr)
subprocess python 3 check_output not same as shell command?

subprocess python 3 check_output not same as shell command?


By : user3837443
Date : March 29 2020, 07:55 AM
will help you shlex.split() syntax is different from the one used by cmd.exe (%COMSPEC%) use raw-string literals for Windows paths i.e., use r'c:\Users' instead of 'c:\Users' you don't need shell=True here and you shouldn't use it with a list argument you don't need to split the command on Windows: string is the native interface
You could use cwd parameter, to run the command in the specified directory:
code :
#!/usr/bin/env python3
import sys
from subprocess import CalledProcessError, STDOUT, check_output

def run_in_path(command, dir_path):
    try: #NOTE: show output only if an error happens   
        ignored = check_output(command, cwd=dir_path, stderr=STDOUT) 
    except CalledProcessError as e:
        sys.stderr.buffer.write(e.output) 
        sys.stderr.buffer.flush()
        return e.returncode
    else:
        return 0
Understanding python subprocess.check_output's first argument and shell=True

Understanding python subprocess.check_output's first argument and shell=True


By : Michael Kesstler
Date : March 29 2020, 07:55 AM
may help you . From the documentation of Popen:
Related Posts Related Posts :
  • How to properly close a QWidget-window in an API with PythonQt
  • How to know which segment a value reside in
  • pandas: convert multiple categories to dummies
  • 'Options' object has no attribute 'get_all_field_names'
  • Customize django filter model field
  • NLTK tag Dutch sentence
  • How to assign a column in 2d-array to some repetitive range using Python?
  • Is there any way to use one static folder for all apps in django project
  • Python Websockets Module has no attribute
  • Python generator next method
  • Is it possible to make pygame work with a slightly newer version of python?
  • to show the weights of edges in a projected network
  • as the missing method of QTabWidget of this code is written?
  • Python - return multiple values using tuple (AWS lambda function)
  • How can I get the text use xpath from the text?
  • Python generator function - is there an excel equivalent?
  • Pandas: fastest way to resolve IP to country
  • Saving huge amount of data (nearly 20 billion entries) in django postgresql
  • Is there a difference between != and <> operators in Python?
  • How to move pointer to specific bytes and read using Pickle Library in Python?
  • Create 2-d array with column keys and row keys in Python
  • Detect match failure in JMESPath
  • python3 django1.8 mysql5.5 gives page not found (404) while sqlite works fine
  • Django forms: List of checkboxes populated from a model
  • Deploying django static files in production
  • How to find the alignment of two data sets in pandas
  • antlr4 + python: debug token match
  • How to 'blit' sprites onto window for a set time
  • Program that checks if a number is prime number
  • python pandas time line graph
  • Reading a text file with OpenCV in Python
  • PyGame in MacOSX: CGContextDrawImage: invalid context 0x0
  • Twisted chat server demo exits immediately
  • How to calculate block averages in pandas DataFrame
  • how to change a list to a specific string.
  • Overlapping text when saving multiple Matplotlib images with text in a loop
  • How do I scrape ONLY <div class ='quotetext'> from a website using python?
  • Python: Float Object is not Iterable
  • ValueError: need more than 3 values to unpack
  • Evaluate while loop at certain point?
  • RxPy - Why are emissions interleaved with merging operators?
  • Spyder - hints disappear too fast
  • Creating a |N| x |M| matrix from a hash-table
  • daily data, resample every 3 days, calculate over trailing 5 days efficiently
  • How to do this program without a counter?
  • Saving a data frame with a column of list in python
  • Python newbie - refactor string function
  • TypeError: deafultdict must have first arguments callable
  • Zero padding not performed properly I think
  • When to bind to attributes that populated with kv-file?
  • Python - Adding "hidden" values to tuples
  • Multselecting in Pandas using .loc
  • python - checking if an array consisting of N integers is a permutation
  • How do you set the outer bg colour of a plot in matplotlib
  • Checking if an input is formatted correctly in Python 3
  • How to restrict two columns not to have the same value using Django?
  • Using turtle in Python to draw six-pointed stars with different side lengths
  • QAbstractListModel does not get updated with values when data is loaded from CSV, but it does when using hardcoded value
  • Python - Modify dictionary from function
  • django-ldap-auth user profile in django > 1.7
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com