Send a command, followed by a command to echo a sentinel, and return without waiting for the command to complete. args: command and arguments, or string printPid: print command's PID? (False)
( self, *args, **kwargs )
| 296 | return None |
| 297 | |
| 298 | def sendCmd( self, *args, **kwargs ): |
| 299 | """Send a command, followed by a command to echo a sentinel, |
| 300 | and return without waiting for the command to complete. |
| 301 | args: command and arguments, or string |
| 302 | printPid: print command's PID? (False)""" |
| 303 | assert self.shell and not self.waiting |
| 304 | printPid = kwargs.get( 'printPid', False ) |
| 305 | # Allow sendCmd( [ list ] ) |
| 306 | if len( args ) == 1 and isinstance( args[ 0 ], list ): |
| 307 | cmd = args[ 0 ] |
| 308 | # Allow sendCmd( cmd, arg1, arg2... ) |
| 309 | elif len( args ) > 0: |
| 310 | cmd = args |
| 311 | # Convert to string |
| 312 | if not isinstance( cmd, str ): |
| 313 | cmd = ' '.join( [ str( c ) for c in cmd ] ) |
| 314 | if not re.search( r'\w', cmd ): |
| 315 | # Replace empty commands with something harmless |
| 316 | cmd = 'echo -n' |
| 317 | self.lastCmd = cmd |
| 318 | # if a builtin command is backgrounded, it still yields a PID |
| 319 | if len( cmd ) > 0 and cmd[ -1 ] == '&': |
| 320 | # print ^A{pid}\n so monitor() can set lastPid |
| 321 | cmd += ' printf "\\001%d\\012" $! ' |
| 322 | elif printPid and not isShellBuiltin( cmd ): |
| 323 | cmd = 'mnexec -p ' + cmd |
| 324 | self.write( cmd + '\n' ) |
| 325 | self.lastPid = None |
| 326 | self.waiting = True |
| 327 | |
| 328 | def sendInt( self, intr=chr( 3 ) ): |
| 329 | "Interrupt running command." |