Strange python error with subprocess.check_call -


i'm having strange error python subprocess.check_call() function. here 2 tests should both fail because of permission problems, first 1 returns 'usage' (the "unexpected behaviour"):

# test #1 import subprocess subprocess.check_call(['git', 'clone', 'https://github.com/achedeuzot/project',                        '/var/vhosts/project'], shell=true)  # shell output usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]            [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]            [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]            [-c name=value] [--help]            <command> [<args>]  commonly used git commands are: [...] 

now second test (the "expected behaviour" one):

# test #2 import subprocess subprocess.check_call(' '.join(['git', 'clone', 'https://github.com/achedeuzot/project',                                 '/var/vhosts/project']), shell=true) # here, we're making string, call should *exactly* same.  # shell output fatal: not create work tree dir '/var/vhosts/project'.: permission denied 

this second error correct one. don't have permissions indeed. why there difference between 2 calls ? thought using single string or list same check_call() function. have read python documentation , various usage examples , both correct.

did have same strange error ? or know why there difference in output when commands should same ?

side notes: python 3.4

remove shell=true first one. if reread subprocess module documentation see. if shell=false (default) first argument list of command line arguments , (or string command, no arguments supplied @ all). if shell=true, first argument string representing shell command line, shell executed, in turn parses command line , splits white space (+ more dangerous things might not want do). if shell=true , first argument list, first list item shell command line, , rest passed arguments shell, not command.

unless know really, need to, let shell=false.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -