我需要从 Powershell 脚本调用 .bat 文件 [英] I need to call .bat file from Powershell script

查看:108
本文介绍了我需要从 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.

这篇关于我需要从 Powershell 脚本调用 .bat 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆