- if VERBOSE_MODE:
- print ("sysexec >>> %s" % cmd)
- prog= popen2.Popen4( cmd, 0 )
- if prog is None:
- raise BootManagerException, \
- "Unable to create instance of popen2.Popen4 " \
- "for command: %s" % cmd
+ try:
+ # Thierry - Jan. 6 2011
+ # would probably make sense to look for | here as well
+ # however this is fragile and hard to test thoroughly
+ # let the caller set 'shell' when that is desirable
+ if shell or cmd.__contains__(">"):
+ prog = subprocess.Popen(cmd, shell=True)
+ if log is not None:
+ log.write("sysexec (shell mode) >>> {}".format(cmd))
+ if VERBOSE_MODE:
+ print("sysexec (shell mode) >>> {}".format(cmd))
+ else:
+ prog = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ if log is not None:
+ log.write("sysexec >>> {}\n".format(cmd))
+ if VERBOSE_MODE:
+ print("sysexec >>> {}".format(cmd))
+ except OSError:
+ raise BootManagerException(
+ "Unable to create instance of subprocess.Popen "
+ "for command: {}".format(cmd))
+ try:
+ (stdoutdata, stderrdata) = prog.communicate()
+ except KeyboardInterrupt:
+ raise BootManagerException("Interrupted by user")