Powershell 运行带有启动进程的.bat文件时
当我直接运行这个.bat文件时,它会执行它应该执行的操作。当我使用start process时,会打开一个黑色窗口,然后立即关闭Powershell 运行带有启动进程的.bat文件时,powershell,batch-file,cmd,Powershell,Batch File,Cmd,当我直接运行这个.bat文件时,它会执行它应该执行的操作。当我使用start process时,会打开一个黑色窗口,然后立即关闭 Start-Process \\server01\f$\filelocation\myfile.bat -Verbose -NoNewWindow 知道它为什么不运行吗 下面是批处理脚本中的内容 MediSpan.Install.exe /Autostart:DEV_Medispan_Data 扩展我的评论: # Simple batch file Get-Con
Start-Process \\server01\f$\filelocation\myfile.bat -Verbose -NoNewWindow
知道它为什么不运行吗
下面是批处理脚本中的内容
MediSpan.Install.exe /Autostart:DEV_Medispan_Data
扩展我的评论:
# Simple batch file
Get-Content -Path 'D:\Temp\abc.bat'
echo off
cls
echo Hello
# Run the .bat file
D:\Temp\abc.bat
# Results - no window is seen unless you are really paying attention since it will flash very fast
<#
Hello
#>
# Using the call operator vs Start-Process
& 'D:\Temp\abc.bat'
# Results - same window response as above
<#
Hello
#>
Start-Process -FilePath ' D:\Temp\abc.bat' -Wait
# Results - same window response as above
<#
no results are displayed
#>
Start-Process -FilePath ' D:\Temp\abc.bat' -PassThru
# Results - same window response as above - But this shows it ran
<#
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
19 3 1536 2524 0.00 10160 11 cmd
#>
$A = Start-Process -FilePath ' D:\Temp\abc.bat'-PassThru;$A.ExitCode
$A
# Results - same window response as above - But this shows it ran
<#
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
0 0 0 0.02 19128
#>
通过TechNet链接从PowerShell调用和3rdP可执行文件
($p = Start-Process -FilePath 'F:\SWDATINSCD_AN_19000101\MediSpan.Install.exe' -ArgumentList '/Autostart:DEV_Medispan_Data' -wait -NoNewWindow -PassThru)
$p.HasExited
$p.ExitCode
$CMD = 'SuperApp.exe'
$arg1 = 'filename1'
$arg2 = '-someswitch'
$arg3 = 'C:\documents and settings\user\desktop\some other file.txt'
$arg4 = '-yetanotherswitch'
& $CMD $arg1 $arg2 $arg3 $arg4
或者像这样:
$AllArgs = @('filename1', '-someswitch', 'C:\documents and settings\user\desktop\some other file.txt', '-yetanotherswitch')
& 'SuperApp.exe' $AllArgs
对于启动过程,按照相同的TechNet链接
($p = Start-Process -FilePath 'F:\SWDATINSCD_AN_19000101\MediSpan.Install.exe' -ArgumentList '/Autostart:DEV_Medispan_Data' -wait -NoNewWindow -PassThru)
$p.HasExited
$p.ExitCode
myfile.bat
中可能有错误,但您尚未向我们展示,因此我们和您一样陷入困境。此外,由于您已经很好地混淆了路径和文件名,我们只能推测-如果其中任何一个包含分隔符,则“引用完整文件名”,因此:“\\server01\f$\filelocation\myfile.bat”
可能会有所帮助。从PowerShell运行外部命令/可执行文件时,它们必须正确格式化才能执行。直接运行批处理文件时没有错误。当它直接运行时,它完全按照它应该做的做。如果我删除-nonewindow,它会提示我运行批处理脚本,我点击ok,然后它就关闭了。我以前运行过其他类似的脚本,从未遇到过类似的问题,所以我认为这是我忘记做的事情。使用呼叫接线员是一个更好的选择。请参阅我的更新以了解您的用例。然而,若你们设置了启动过程,你们可以看到我的更新。请参阅我的第二次更新。
($p = Start-Process -FilePath 'F:\SWDATINSCD_AN_19000101\MediSpan.Install.exe' -ArgumentList '/Autostart:DEV_Medispan_Data' -wait -NoNewWindow -PassThru)
$p.HasExited
$p.ExitCode