簡體   English   中英

通過 cmd.exe 調用的 powershell.exe 命令中的嵌套 cmd.exe 命令

[英]Nested cmd.exe command within a powershell.exe command called through cmd.exe

是否可以設置這樣的腳本:

file.exe [CMD(POWERSHELL(CMD))]

這是我現在的代碼, (結合我在這里得到的答案)

:RETURN
powershell -command "Start-Process -FilePath '\\my\file\path\myapplication.exe'"
powershell -command "if (gps | ? {$_.mainwindowtitle} | select name, id, mainwindowtitle | where {$_.Name -match 'myapplication'}) { Write-Output 'App verified, running in Taskbar.'} else { Write-Output 'App no running in Taskbar, checking again.' cmd.exe /c 'GOTO RETURN' }"

上述批處理文件已轉換為 .exe。

我的主要問題是cmd.exe /c 'GOTO RETURN'被讀取為Write-Output而不是代碼。

所以,如果我解析正確:

您有一個 cmd 腳本,您正在調用 powershell 進行一些檢查,並希望根據此 powershell 命令的結果采取行動。

如果是這樣,那么您必須更改要在For /F循環內完成的對 powershell 的調用以捕獲它的輸出。

這是我在手機上做的一個未經測試的例子:

 :RETURN

 #command lines here

 For /F "Tokens=*" %%A IN ('
   Powershell -command "if (gps ^| ? {$_.mainwindowtitle} ^| select name, id, mainwindowtitle ^| where {$_.Name -match ^'myapplication^'}^) { ^'App verified, running in Taskbar.^' } else { ^'App no running in Taskbar, checking again.^' }"
 ') DO (
   IF /I "%%A" EQU "App no running in Taskbar, checking again." (
     GOTO :RETURN
   )
 )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM