3

I'd like run a .exe which could be in a number of locations.

$runpath = "$servicepackfolder\SQLServer2008SP1-KB968369-IA64-ENU.exe"

Start-Process -FilePath $runpath -arg "/x:.\$buildfolder\PCU" 

Or this way, specifying the WorkingDirectory:

Start-Process 'SQLServer2008SP1-KB968369-IA64-ENU.exe' -WorkingDirectory $servicepackfolder -arg "/x:.\$buildfolder\PCU"

But it seems the variables are not being interpreted as strings.

Start-Process : This command cannot be executed due to the error: The system cannot find the file specified.

I am in the correct directory and if I take the output from the $runpath variable and substitute it for the variable in the Start-Process call, I get the expected behavior.

Will this work, or am I stuck hardcoding these paths. Trying to automate the slipstream build process for SQL 2008.

1
  • Did you ever figure out if you could do this? Commented Jan 27, 2014 at 14:36

2 Answers 2

1

I can duplicate the behavior you see if I add -NoNewWindow but if I don't specify that parameter it works as expected for my test case:

start-process sizeof.exe  -WorkingDirectory C:\temp -ArgumentList 1

The new window flashes up and goes away but I can see it is running the specified exe from my temp dir.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm trying to use a variable for the value of a parameter. It looks like you have it hard coded there.
Using a variable would work just as well - -ArgumentList $myvar. Are you using -NoNewWindow?
@KeithHill - try replacing sizeof.exe with a variable that holds the same textual value.
0

Better late than never, but I've found a workaround for this when having the same issue, not sure if it is classed as a bug or not -

Powershell doesn't always handle un-escaped backslashes or quotes in the strings that are stored in a variable / created by string processing all that well for -FilePath, so for your line:

$runpath = "$servicepackfolder\SQLServer2008SP1-KB968369-IA64-ENU.exe"

Try the following (or equivalent) before using $runpath:

$cleanpath = $runpath.replace("\","\\").replace('"',"")

The .replace("\","\\").replace('"',"") escapes the slashes and eliminates the quotes that the string handling and passing introduce, which seems to clear this issue (for some cases).

Bit late for you I imagine but hopefully this helps other people googling for this one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.