Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing an exe with arguments using Powershell

Tags:

powershell

This is what I want to execute:

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

This is what I have tried:

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

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

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

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

&$Viewpoint $a $b $c

When I execute this I receive an error stating:

File C:\viewpointfile.vpt "/D:C:($BEGDATE to $TODDATE).xls" not found!

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! :)

Update

manojlds suggested echoargs so here it the output from it:

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

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

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

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

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

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.

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

like image 653
Chris Avatar asked Dec 17 '22 07:12

Chris


1 Answers

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/

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
"@
like image 174
Chad Miller Avatar answered Feb 22 '23 06:02

Chad Miller