Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

python - @pause in .bat file prevents subprocess.Popen from finishing

I'm trying to pipe the output of a simple .bat script to my python script using the following code (Win10 btw):

import subprocess

p = subprocess.Popen(C:UsersPublicgamess-64get-version-names.bat), stdout=subprocess.PIPE)
output = p.communicate()
print(output)

The problem is that the script looks like this:

::
::   Mar   08, 2015 :: Sarom Leang :: get-version-names.bat
::
:: Looks in current directory for gamess.*.exe and outputs the
:: version names to be used in 'rungms.bat' or 'rungms-serial.bat'
::
@setlocal enabledelayedexpansion
@echo ------                        -------
@echo Binary                        Version
@echo ======                        =======
@echo.
@for %%f in (gamess.*.exe) do @(
@set temp=%%~nf
@set version=!temp:gamess.=!
@echo %%f       !version!)
@echo.
@pause

The @pause prevents my py script from getting past subprocess.pOpen() so I wanted to know how to get the stdout without my script being stopped in it's tracks (And without just deleting the @pause).

question from:https://stackoverflow.com/questions/65945793/pause-in-bat-file-prevents-subprocess-popen-from-finishing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...