Fix popen() to work properly with shell=True
This commit is contained in:
+4
-4
@@ -383,23 +383,23 @@ class Node( object ):
|
|||||||
'mncmd':
|
'mncmd':
|
||||||
[ 'mnexec', '-da', str( self.pid ) ] }
|
[ 'mnexec', '-da', str( self.pid ) ] }
|
||||||
defaults.update( kwargs )
|
defaults.update( kwargs )
|
||||||
|
shell = defaults.pop( 'shell', False )
|
||||||
if len( args ) == 1:
|
if len( args ) == 1:
|
||||||
if isinstance( args[ 0 ], list ):
|
if isinstance( args[ 0 ], list ):
|
||||||
# popen([cmd, arg1, arg2...])
|
# popen([cmd, arg1, arg2...])
|
||||||
cmd = args[ 0 ]
|
cmd = args[ 0 ]
|
||||||
elif isinstance( args[ 0 ], BaseString ):
|
elif isinstance( args[ 0 ], BaseString ):
|
||||||
# popen("cmd arg1 arg2...")
|
# popen("cmd arg1 arg2...")
|
||||||
cmd = args[ 0 ].split()
|
cmd = [ args[ 0 ] ] if shell else args[ 0 ].split()
|
||||||
else:
|
else:
|
||||||
raise Exception( 'popen() requires a string or list' )
|
raise Exception( 'popen() requires a string or list' )
|
||||||
elif len( args ) > 0:
|
elif len( args ) > 0:
|
||||||
# popen( cmd, arg1, arg2... )
|
# popen( cmd, arg1, arg2... )
|
||||||
cmd = list( args )
|
cmd = list( args )
|
||||||
|
if shell:
|
||||||
|
cmd = [ os.environ[ 'SHELL' ], '-c' ] + [ ' '.join( cmd ) ]
|
||||||
# Attach to our namespace using mnexec -a
|
# Attach to our namespace using mnexec -a
|
||||||
cmd = defaults.pop( 'mncmd' ) + cmd
|
cmd = defaults.pop( 'mncmd' ) + cmd
|
||||||
# Shell requires a string, not a list!
|
|
||||||
if defaults.get( 'shell', False ):
|
|
||||||
cmd = ' '.join( cmd )
|
|
||||||
popen = self._popen( cmd, **defaults )
|
popen = self._popen( cmd, **defaults )
|
||||||
return popen
|
return popen
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user