Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

powershell and calling external executables

0 views
Skip to first unread message

Sam Leibowitz

unread,
Aug 31, 2007, 2:30:41 PM8/31/07
to
All,

Sorry if this has been asked and answered - the problem I'm having is
a big different from the standard "how do I run an exe from a
powershell script" that comes up all the time.

I'm trying to call an executable file that accepts several command-
line arguments from a Powershell script. The current line in the
script which starts our build process looks like this:

cmd /c "$makevb_program -path=$LOCAL_DIR\MAK\ -auto=N $MAKEVB_ARGS"

$makevb_program contains the full path to our compile utility.

What I would like to do is replace that with a & call, because I would
prefer to let powershell complete the script and exit rather than hang
while waiting for the build program to execute. I've tried this:

& "$makevb_program -path=$LOCAL_DIR\MAK\ -auto=N $MAKEVB_ARGS"

But I get the "is not recognized as a cmdlet, function, etc" error.

Is there a way to call an EXE file, with command line arguments, in
this way?

Thanks,
Sam

Hal Rottenberg

unread,
Aug 31, 2007, 2:50:35 PM8/31/07
to
Sam Leibowitz wrote:

> & "$makevb_program -path=$LOCAL_DIR\MAK\ -auto=N $MAKEVB_ARGS"

Invoke-Expression should do it. I don't know why & won't though...


--

Hal Rottenberg
blog: http://halr9000.com
powershell category:
http://halr9000.com/article/category/programming/scripting/powershell/

Shay Levi

unread,
Aug 31, 2007, 2:54:33 PM8/31/07
to
Im not sure, but try:

& "$makevb_program" "-path=$LOCAL_DIR\MAK\" "-auto=N" "$MAKEVB_ARGS"

If you have PSCX (PowerShell Community Extensions) installed you can use
echoargs.exe. This
awesome utility can help you "see" how the target file/function processes
the arguments sent to it, thus
troubleshooting any argument related errors

Or visit here http://scriptolog.blogspot.com/2007/08/things-that-make-you-go.html
to get the PowerShell Version of echoargs.

Shay
http://scriptolog.blogspot.com

Kiron

unread,
Aug 31, 2007, 2:54:51 PM8/31/07
to
Try Invoke-Expression instead of the call\invoke operator '&':

iex "$makevb_program -path=$LOCAL_DIR\MAK\ -auto=N $MAKEVB_ARGS"

# iex is Invoke-Expression's alias

--
Kiron

Sam Leibowitz

unread,
Aug 31, 2007, 3:23:39 PM8/31/07
to
Thanks Kiron & Hal - it turns out that it works fine using iex, but
not &.

(Actually... it worked fine after I escaped all the hyphens. Oops.)

Also, thanks Shay for the reference to PSCX. I'm a PS newbie, although
I've done a fair amount of shell scripting in my Unix life, and I
expect that the extensions will be very helpful to me.

- Sam

he...@hotmail.co.uk

unread,
Sep 2, 2007, 3:29:29 PM9/2/07
to

Can't improve much on the above method, but another way is to add the
exe folder to your path:

$env:path += ";C:\Program Files\makevb_program"

Then you can just call it from the PS prompt without the hoohah:

makevb_program -path=$LOCAL_DIR\MAK\ -auto=N $MAKEVB_ARGS

-Hecks


0 new messages