![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Problems running an app from within a script I have a simple and basic question about running external apps from a script. If, within a script, I have this: ----------------------------------------- $Path = "C:\Temp" TestApp.exe "$Path\File.txt" ----------------------------------------- ...then it works fine. However, if I have this: ----------------------------------------- $TextEditor = "TestApp.exe" $Path = "C:\Temp" $TextEditor + " " + "`"$Path\File.txt`"" ----------------------------------------- ...what happens is that the line is displayed like a text string, but never actually executed. What am I doing wrong? Steve |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Problems running an app from within a script On Jan 28, 10:17*pm, "Aether" <n...@xxxxxx> wrote:
You have to use that string as a -command parameter for cmdlet invoke- expression (Runs a Windows PowerShell expression that is provided in the form of a string.) like: invoke-expression -command ($TextEditor + " " + "`"$Path\File.txt`"") or invoke-expression ($TextEditor + " " + "`"$Path\File.txt`"") or even shorter (if you use it in a console) iex ($TextEditor + " " + "`"$Path\File.txt`"") Regards, Aleksandar | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: Problems running an app from within a script Thats because its just a string. Consider this: PS > "notepad.exe" notepad.exe notepad is not executed, it is treated as a string. To invoke it: $n = "notepad.exe" $file = "$profile" invoke-expression "$n $file" This will load your profile into notepad. Likewise, you can use the Call operator (&): & $n $file ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Problems running an app from within a script "Shay Levi" <no@xxxxxx> wrote in message news:8766a9441c0df8ca301de3cc292e@xxxxxx
Thank you both, that did the trick. ![]() Steve | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Running PowerShell Script from TaskScheduler | malckelly | PowerShell | 3 | 11-22-2007 10:11 PM |
| Logon script not running? | Murphy Wong | Vista General | 2 | 08-25-2007 06:44 AM |
| trouble running a script | BJ Daniels | PowerShell | 3 | 08-20-2007 03:10 PM |
| Running an HTA or WSH script as administrator | Vista security | 3 | 01-10-2007 10:49 AM | |
| Help on running a a script | Toxic | PowerShell | 3 | 12-05-2006 11:35 AM |