本文介绍了使用 Powershell 执行带参数的 exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要执行的:

c:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe/Setvar((POSTSTR $POSTSTR)(POSTEND $POSTEND))/G:C:\viewpointfile.vpt/D:C:($BEGDATE to$TODDATE).xls

这是我尝试过的:

$a = "/Setvar((POSTSTR $POSTSTR)(POSTEND $POSTEND))"

$b = "/G:C:\viewpointfile.vpt"

$b = "/G:C:\viewpointfile.vpt"

$c = "/D:C:($BEGDATE 到 $TODDATE).xls"

$c = "/D:C:($BEGDATE to $TODDATE).xls"

$Viewpoint = "c:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe"

$Viewpoint = "c:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe"

&$Viewpoint $a $b $c

&$Viewpoint $a $b $c

当我执行此操作时,我收到一条错误消息:

When I execute this I receive an error stating:

文件 C:\viewpointfile.vpt /D:C:($BEGDATE to $TODDATE).xls"没有找到!

我不确定它从哪里获得额外的引号.如果我只用 $a 和 $b 运行命令,它运行良好.

I'm not sure where it gets the extra quotes from. If I run the command with just $a and $b it runs fine.

任何帮助将不胜感激.谢谢!:)

Any help would be greatly appreciated. Thanks! :)

更新

manojlds 建议了 echoargs 所以这里是它的输出:

manojlds suggested echoargs so here it the output from it:

&./echoargs.exe $viewpoint $a $b $c

Arg 0 是 C:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe

Arg 0 is C:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe

Arg 1 是/Setvar((POSTSTR 20101123)(POSTEND 20111123))

Arg 1 is /Setvar((POSTSTR 20101123)(POSTEND 20111123))

参数 2 是/G:C:\viewpointfile.vpt

Arg 2 is /G:C:\viewpointfile.vpt

Arg 3 是/D:C:(2010-11-23 到 2011-11-23 PM).xls

Arg 3 is /D:C:(2010-11-23 to 2011-11-23 PM).xls

似乎所有参数都被正确传递.当我在 cmd.exe 中将此作为命令运行时,它执行得很好.因此,Powershell 端的某些内容一定会弄乱输出.

It appears that all the arguments are being passed properly. When I run this as a command in cmd.exe it executes perfectly. So something on Powershells end must be messing up the output.

是否有其他方法可以使用 Powershell 执行此命令?

Is there any other way to go about executing this command using Powershell?

推荐答案

我发现 Joel Bennett 发表的博客中的方法在调用遗留命令时最可靠

I've found the method blogged by Joel Bennett to be the most reliable when calling legacy commands

http://huddledmasses.org/the-problem-with-calling-legacy-or-native-apps-from-powershell/

从 Powershell 调用 LogParser 时我不得不使用它:

I've had to use this when calling LogParser from Powershell:

set-alias logparser "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe"
start-process -NoNewWindow -FilePath logparser -ArgumentList @"
"SELECT * INTO diskspaceLP FROM C:\Users\Public\diskspace.csv" -i:CSV -o:SQL -server:"Win7boot\sql1" -database:hsg -driver:"SQL Server" -createTable:ON
"@

这篇关于使用 Powershell 执行带参数的 exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:49