第二个蝙蝠未执行PowerShell脚本

发布于 2025-02-13 10:49:08 字数 214 浏览 0 评论 0原文

PowerShell脚本调用以下BAT文件,但是仅执行BAT1.BAT

#first bat

Start-Process "C:\bat1.bat" -Wait

#run second bat
Start-Process "C:\bat2.bat" -Wait

#run last bat  
cmd.exe /c '\last.bat'

the below bat files are being called by PowerShell script, however only bat1.bat is executed the others bat2.bat and last.bat are not being called

#first bat

Start-Process "C:\bat1.bat" -Wait

#run second bat
Start-Process "C:\bat2.bat" -Wait

#run last bat  
cmd.exe /c '\last.bat'

You r support is highly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说好的呢 2025-02-20 10:49:08

尝试使用以下操作:

Set-Location C:\temp

Start-Process .\bat1.bat -Wait
Write-Host "bat1.bat DONE"

Start-Process .\bat2.bat -Wait
Write-Host "bat2.bat DONE"

cmd /c .\last.bat
Write-Host "last.bat DONE"

我制作了以下.bat文件:

bat1.bat

@ECHO OFF
ECHO bat1
PAUSE

bat2.bat

@ECHO OFF
ECHO bat2
PAUSE

final.bat

@ECHO OFF
ECHO final

当PS脚本运行时,所有3次运行。

如果以前的过程完成,则将写入主机放在控制台中。

编辑:

对不起,我以前没有给出太多解释。

您的问题是,一个.bat文件之一未完成。

您的语法应该运行bat1.bat和bat2.bat。 “ cmd.exe /c” \ last.bat“将失败。 。

​不是.bat代码。

验证您的脚本将运行,我不需要使用设置。进入下一个过程。

Try using this:

Set-Location C:\temp

Start-Process .\bat1.bat -Wait
Write-Host "bat1.bat DONE"

Start-Process .\bat2.bat -Wait
Write-Host "bat2.bat DONE"

cmd /c .\last.bat
Write-Host "last.bat DONE"

I made the following .bat files:

bat1.bat

@ECHO OFF
ECHO bat1
PAUSE

bat2.bat

@ECHO OFF
ECHO bat2
PAUSE

final.bat

@ECHO OFF
ECHO final

When the PS script was ran, all 3 ran as one would expect.

Putting the Write-Host will show in the console if the previous process finished.

Edit:

I didn't give much explanation before, sorry.

Your issue is that one of the .bat files is not finishing.

The syntax you had should have run bat1.bat and bat2.bat. The "cmd.exe /c "\last.bat" would fail. You need the "c:\last.bat" if you aren't going to set the path to c:. If you did that, you would want ".\last.bat"

To make sure that your script would work, I made 3 basic .bat files whose functions were solely to log a string associated with them. Doing this guaranteed that if anything went wrong, it was with the PS code and not the .bat code.

After verifying your script would run, I made the one I provided. Using Set-location isn't necessary, but I think it makes the code look cleaner. The Write-Host after each process is logging in the PS console that the script is moving on to the next process.

梦屿孤独相伴 2025-02-20 10:49:08

为什么不尝试

CALL "C:\bat1.bat"
CALL "C:\bat2.bat"
\last.bat

完全避免Powersmell?

Why not try

CALL "C:\bat1.bat"
CALL "C:\bat2.bat"
\last.bat

and avoid Powersmell altogether?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文