##// END OF EJS Templates
procutil: allow to specify arbitrary stdin bytes to runbgcommand...
marmoute -
r46371:37c65704 default
parent child Browse files
Show More
@@ -635,21 +635,35 b' if pycompat.iswindows:'
635 stderr=None,
635 stderr=None,
636 ensurestart=True,
636 ensurestart=True,
637 record_wait=None,
637 record_wait=None,
638 stdin_bytes=None,
638 ):
639 ):
639 '''Spawn a command without waiting for it to finish.'''
640 '''Spawn a command without waiting for it to finish.'''
640 # we can't use close_fds *and* redirect stdin. I'm not sure that we
641 # we can't use close_fds *and* redirect stdin. I'm not sure that we
641 # need to because the detached process has no console connection.
642 # need to because the detached process has no console connection.
642 p = subprocess.Popen(
643
643 tonativestr(script),
644 try:
644 shell=shell,
645 stdin = None
645 env=tonativeenv(env),
646 if stdin_bytes is not None:
646 close_fds=True,
647 stdin = pycompat.unnamedtempfile()
647 creationflags=_creationflags,
648 stdin.write(stdin_bytes)
648 stdout=stdout,
649 stdin.flush()
649 stderr=stderr,
650 stdin.seek(0)
650 )
651
651 if record_wait is not None:
652 p = subprocess.Popen(
652 record_wait(p.wait)
653 tonativestr(script),
654 shell=shell,
655 env=tonativeenv(env),
656 close_fds=True,
657 creationflags=_creationflags,
658 stdin=stdin,
659 stdout=stdout,
660 stderr=stderr,
661 )
662 if record_wait is not None:
663 record_wait(p.wait)
664 finally:
665 if stdin is not None:
666 stdin.close()
653
667
654
668
655 else:
669 else:
@@ -662,6 +676,7 b' else:'
662 stderr=None,
676 stderr=None,
663 ensurestart=True,
677 ensurestart=True,
664 record_wait=None,
678 record_wait=None,
679 stdin_bytes=None,
665 ):
680 ):
666 '''Spawn a command without waiting for it to finish.
681 '''Spawn a command without waiting for it to finish.
667
682
@@ -722,15 +737,21 b' else:'
722 if record_wait is None:
737 if record_wait is None:
723 # Start a new session
738 # Start a new session
724 os.setsid()
739 os.setsid()
740 # connect stdin to devnull to make sure the subprocess can't
741 # muck up that stream for mercurial.
742 if stdin_bytes is None:
743 stdin = open(os.devnull, b'r')
744 else:
745 stdin = pycompat.unnamedtempfile()
746 stdin.write(stdin_bytes)
747 stdin.flush()
748 stdin.seek(0)
725
749
726 stdin = open(os.devnull, b'r')
727 if stdout is None:
750 if stdout is None:
728 stdout = open(os.devnull, b'w')
751 stdout = open(os.devnull, b'w')
729 if stderr is None:
752 if stderr is None:
730 stderr = open(os.devnull, b'w')
753 stderr = open(os.devnull, b'w')
731
754
732 # connect stdin to devnull to make sure the subprocess can't
733 # muck up that stream for mercurial.
734 p = subprocess.Popen(
755 p = subprocess.Popen(
735 cmd,
756 cmd,
736 shell=shell,
757 shell=shell,
@@ -754,5 +775,6 b' else:'
754 finally:
775 finally:
755 # mission accomplished, this child needs to exit and not
776 # mission accomplished, this child needs to exit and not
756 # continue the hg process here.
777 # continue the hg process here.
778 stdin.close()
757 if record_wait is None:
779 if record_wait is None:
758 os._exit(returncode)
780 os._exit(returncode)
General Comments 0
You need to be logged in to leave comments. Login now