powershell - 批处理在后台运行
问题描述
我正在使用 CA 工作负载自动化,我告诉它运行批处理文件或 ps 文件,它确实可以,但是我告诉它运行的东西,它在后台运行它们,有没有办法强制批处理文件运行视觉上在前景中?
编辑
start /wait /d"C:\Turing\App\" TuringExpo.exe "456555384" "Test"
start /wait /d"C:\Program Files\Microsoft Office\root\Office16\" winword.exe
解决方案
至于这个……
'在后台批量运行'
有没有办法强制批处理文件在前台运行?
... PowerShell 当您调用外部文件(即 .exe 或 .bat)时,定义了调用这些文件并解决您的用例的方法。这在整个网络上都有很好的记录。如前所述,这些命令不是 PowerShell,它们只是 PowerShell 脚本中的批处理内容,或者我假设这些是您的批处理文件中的内容。
话虽如此,调用外部文件的过程已定义。
没有必要将其作为批处理文件执行。只需在 PowerShell 脚本中直接调用它。
另请参阅以下详细信息---
# Example(s):
& 'C:\Program Files\Windows Media Player\wmplayer.exe' "c:\videos\my home video.avi" /fullscreen
<#
Things can get tricky when an external command has a lot of parameters or there
are spaces in the arguments or paths!
With spaces, you have to nest Quotation marks and the result it is not always
clear!
In this case, it is better to separate everything like so:
#>
$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
# or something like this:
$AllArgs = @('filename1', '-someswitch', 'C:\documents and settings\user\desktop\some other file.txt', '-yetanotherswitch')
& 'SuperApp.exe' $AllArgs
<#
** This method should no longer be used with V3
Why: Bypasses PowerShell and runs the command from a cmd shell. Often times used
with a DIR which runs faster in the cmd shell than in PowerShell (NOTE: This was
an issue with PowerShell v2 and its use of .Net 2.0, this is not an issue with
V3).
Details: Opens a CMD prompt from within PowerShell and then executes
the command and returns the text of that command. The /c tells CMD that
it should terminate after the command has completed. There is little to
no reason to use this with V3.
#>
# Example:
<#
runs DIR from a cmd shell, DIR in PowerShell is an alias to GCI. This will
return the directory listing as a string but returns much faster than a GCI
#>
cmd /c dir c:\windows
也可以看看
正确完成 PowerShell 和外部命令 ' https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right '
使用 Windows PowerShell 运行旧的命令行工具(以及它们最奇怪的参数)
引用细节 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules
所以这 ...
start /wait /d"C:\Turing\App\" TuringExpo.exe "456555384" "Test"
start /wait /d"C:\Program Files\Microsoft Office\root\Office16\" winword.exe
...可能成为链接这个的东西,只需使用 PowerShell,不涉及批处理文件:
Start-Process -FilePath 'C:\Turing\App\TuringExpo.exe' -ArgumentList '456555384', 'Test' -Wait
Start-Process -FilePath winword -Wait
推荐阅读
- php - 如何在 yii2 gridview 中根据条件隐藏列?
- azure-devops - 在 azure devops 中使用 azure powershell 内联任务获取 azure 功能键并将其放入 keyvault 的脚本
- java - Intellij 将私有字段及其访问器方法移动/重构到不同的类
- node.js - 无法保存 ids 数组 mongo
- elasticsearch - 密集向量数据类型的 Elasticseach 错误,值为空
- c# - 在命令提示符下工作的命令在 C# 中不起作用
- python - 如何通过读取文本文件中提到的日期来计算总天数?
- mysql - 如何从两个表中获取空值 WHERE user_id IS NULL 在 Node.js MYSQL 中不起作用
- python - Django:与多对多关系相关的问题
- javascript - 属性“z”的唯一值