![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Running a Command line script from within powershell. I have a 3rd party command line tool I need to run from within a powershell script. What is the current method for doing this? I need the calling powershell script to wait for the 3rd party tool to finish before moving on... the tool has a number of input I need to provide... I'm trying to do something like this ! $Tool="D:\tool.exe" $Password="passw0rd" $InputFile="D:\tmp\input.txt" $CmdLine = $Tool + " -u=User -p=" + $Password + " -i=" + $InputFile +" -m=mode" NOW HOW WOULD I RUN THE $CmdLine !? Thanks in advance. Russ. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Running a Command line script from within powershell. Invoke-Expression |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Running a Command line script from within powershell. Pipe it to out-null to make the current command wait until it finishes before moving on. ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > I have a 3rd party command line tool I need to run from within a > powershell script. > What is the current method for doing this? I need the calling > powershell script to wait for the 3rd party tool to finish before > moving on... > the tool has a number of input I need to provide... > > I'm trying to do something like this ! > > $Tool="D:\tool.exe" > $Password="passw0rd" > $InputFile="D:\tmp\input.txt" > $CmdLine = $Tool + " -u=User -p=" + $Password + " -i=" + $InputFile +" > -m=mode" > > NOW HOW WOULD I RUN THE $CmdLine !? > > Thanks in advance. > Russ. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Running a Command line script from within powershell. invoke-expression doesn't appear to do anything !? I've tried the command line in a dos prompt and it works fine. Any other ideas out there please? I've tried : invoke-expression -command $CmdLine and invoke-expression -command $CmdLine | out-null Neither appear to even attempt to run the $CmdLine. Thanks Again. Russ |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Running a Command line script from within powershell. Runing native commands (executables) in PowerShell is much like running them in DOS, type: ipconfig /all and get the output just as if you typed it in CMD. As for your 3rd party tool, I can't test its exact parameters but the above can be a candidate to explain how to invoke commands: $tool="ipconfig.exe" $cmdLine = "/all" invoke-expression "$tool $cmdLine" Then pipe to out-null invoke-expression "$tool $cmdLine" | out-null ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > invoke-expression doesn't appear to do anything !? I've tried the > command line in a dos prompt and it works fine. > > Any other ideas out there please? > > I've tried : > > invoke-expression -command $CmdLine > and > invoke-expression -command $CmdLine | out-null > Neither appear to even attempt to run the $CmdLine. > > Thanks Again. > Russ |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Running a Command line script from within powershell. Hi Shay, Even if I simplify the commandline down to the absolute minimum, powershell doesn't even attempt to run it? is there a security issue here maybe? I've tested invoke-expression with a dir listing, works fine. I've tried putting the EXE line in a BAT file and executing that, It runs the BAT and does DOS commands within but will not run the EXE. $Test = "dir > D:\Teamcenter\import\tmp\test.out" invoke-expression -command "$Test" # WORKS Invoke-Expression -Command "D:\ren\ips \v2007\ips_data_upload_2007_6_7_1_nti.exe" # FAILS - Doesn't even attempt to run the EXE. Just to reiterate the EXE does work normally via DOS. All ideas/suggestion greatly appreciated! Cheers Russ |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Running a Command line script from within powershell. It should run. Take the tasklist.exe for example: invoke-expression "C:\windows\system32\tasklist.exe" Another way is to invoke commands is with the Call operator (ampersand sign): & "C:\windows\system32\tasklist.exe" /SVC There is also a great blog post by Keith Hill (I recommend the whole series): Effective PowerShell Item 10: Understanding PowerShell Parsing Modes http://keithhill.spaces.live.com/Blo...A97!6058.entry ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > Hi Shay, > > Even if I simplify the commandline down to the absolute minimum, > powershell doesn't even attempt to run it? is there a security issue > here maybe? > > I've tested invoke-expression with a dir listing, works fine. > I've tried putting the EXE line in a BAT file and executing that, It > runs the BAT and does DOS commands within but will not run the EXE. > $Test = "dir > D:\Teamcenter\import\tmp\test.out" > invoke-expression -command "$Test" > # WORKS > Invoke-Expression -Command "D:\ren\ips > \v2007\ips_data_upload_2007_6_7_1_nti.exe" > # FAILS - Doesn't even attempt to run the EXE. > Just to reiterate the EXE does work normally via DOS. > > All ideas/suggestion greatly appreciated! > > Cheers > Russ |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Running a Command line script from within powershell. Hi Shay. Thanks for the responses, I've found the issue!.. I need to use invoke-item not invoke-expression. Thanks for your help. Cheers Russ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How to pass the name of a PowerShell script as a command line para | PowerShell | |||
| noob: PS script fails, but runs from command line | PowerShell | |||
| Running a command from inside a script, command line is corrupted | PowerShell | |||
| Script from command-line | PowerShell | |||
| Running PS1 file from command line | PowerShell | |||