5

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?

Community
  • 1
  • 1
Chris
  • 53
  • 1
  • 4

3 Answers3

5

If I can't run a command like this it usually works for me with Invoke-Expression. Can't test yours though.

Invoke-Expression "$viewpoint $a $b $c"
Tom
  • 1,611
  • 1
  • 13
  • 16
4

Get echoargs.exe from Powershell community extension ( http://pscx.codeplex.com/ ) to figure out the arguments that Powershell sends to your exe.

$a = "/Setvar((POSTSTR $POSTSTR)(POSTEND $POSTEND))"
$b = "/G:C:\viewpointfile.vpt"
$c = "/D:C:($BEGDATE to $TODDATE).xls"
$echoArgs = ".\echoargs.exe"
&$echoArgs $a $b $c

You seem to be passing the arguments fine however, but the viewpoint.exe seems to be acting up. I don't see what you are doing here:

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

After C: there is no \ and also your error message that you have pasted shows $BEGDATE and $TODDATE verbatim, which is not possible as they would have been substituted with their values.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Thanks for your reply. $BEGDATE and $TODDATE are being substituted properly I just had a brain-fart while typing it. Same goes for the C:\ issue. I have tested the arguments using echoArgs and updated my post. – Chris Nov 23 '11 at 21:56
4

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
"@
Chad Miller
  • 40,127
  • 3
  • 30
  • 34