2

I have following PowerShell script:

cmd /c script1.bat
cmd /c script2.bat

script1.bat at the end of execution have "pause" command, so the execution of my PS script stops.

How can send any key cmd.exe to avoid stopping script execution? NOTE: I can't change batch scripts - they are 3rd party.

4

4 に答える 4

6

You can pipe input to the program (cmd.exe) like this:

"X" | cmd /c script1.bat

于 2013-01-16T17:50:21.737 に答える
0

You could put an empty file called pause.bat in the same directory. Then it would do nothing instead of pause.

于 2013-01-16T16:41:32.000 に答える
0

The batch scripts may be 3rd party, but surely you can just a copy/backup and edit the content to remove the PAUSE command?

I sometimes put a PAUSE in if I am testing something and don't want the window to close, but otherwise I can't think of a good reason to keep that in.

于 2013-01-16T16:43:17.877 に答える
-1

I had trouble getting the accepted answer to work for me due having an expression in the bat file path.

"x" | $Env:WRAPPER_HOME\bat\installService.bat $LOGFILE

Error is "Expressions are only allowed as the first element of a pipeline."

Here's what I got working (finally):

[PS script code]

& runner.bat bat_to_run.bat logfile.txt

[runner.bat]

@echo OFF

REM This script can be executed from within a powershell script so that the bat file
REM passed as %1 will not cause execution to halt if PAUSE is encountered.
REM If {logfile} is included, bat file output will be appended to logfile.
REM
REM Usage:
REM runner.bat [path of bat script to execute] {logfile}

if not [%2] == [] GOTO APPEND_OUTPUT
@echo | call %1
GOTO EXIT

:APPEND_OUTPUT
@echo | call %1  1> %2 2>&1

:EXIT
于 2020-02-21T14:56:59.017 に答える