我需要从 Powershell 脚本调用 .bat 文件
问题描述:
我们正在将 perl 脚本迁移到 powershell 脚本.Perl中的代码如下所示
We are migrating perl script to powershell script. In Perl the code is as shown below
$rc='D:\\EmailConnector\\run.bat> $EmailConnector_log;';
我尝试过如下图但没有工作
I tried as shown below but not working
StartProcess "cmd.exe" "/c D:\EmailConnector\run.bat> $EmailConnector_log"
当我尝试如下所示的 .bat 脚本运行时,但我想更新日志文件.你能帮我解决这个问题吗.
When I tried as shown below the .bat script ran, but I want to update the log file. Could you help me on this.
StartProcess run.bat -workingdirectory "D:\EmailConnector"
.bat 文件由用于电子邮件功能的 jar 文件组成.但是我们想获取登录日志文件.
The .bat file consist of jar file for email functionality. But we want to get log in log file.
答
使用 调用运算符 (&
),像这样:
Use the call operator (&
), like this:
& 'D:\EmailConnector\run.bat' > $EmailConnector_log
批处理脚本的返回值自动放入变量$LastExitCode
.
The return value of the batch script is automatically put into the variable $LastExitCode
.