![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Executing batch files in PS scripts I am have a trouble writing a PowerShell wrapper around some batch files. I have a wrapper working using WScript/VBScript but I would like to move to PowerShell. The working WScript/VBScript code echos 'y' into a make.bat prompt. CODE 123 VER 1.2.3 are parameters for make.bat and I'm redirecting stderr to stdout. Stdout is dumped into a log file (and monitored for errors, code not shown). set oExec = oShell.Exec("%comspec% /c echo y | make.bat CODE 123 VER 1.2.3 2>&1") Do Until oExec.StdOut.AtEndOfStream sReadLine = oExec.StdOut.ReadLine() fLog.Writeline sReadLine loop I can get the make batch file to run and pipe 'y' into it, but can't get the parameters passed into it. echo y | make.bat "CODE 123 VER 1.2.3 2>&1" >build.log Is there a PowerShell method of implementing the 'Do Until oExec.StdOut.AtEndOfStream sReadLine = oExec.StdOut.ReadLine()' functionality? TIA |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Executing batch files in PS scripts > Is there a PowerShell method of implementing the > > 'Do Until oExec.StdOut.AtEndOfStream > sReadLine = oExec.StdOut.ReadLine()' > > functionality? Don't have the time to try out the DOS part right now. You're looking to just capture what's going on like a logfile? Might start-transcript/stop-transcript work for you? Marco |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Executing batch files in PS scripts Thanks for the suggestion Marco. I think I need to use the Tee-Object cmdlet to pipe the output to a file and process the stream for errors. "Marco Shaw" wrote: > > > Is there a PowerShell method of implementing the > > > > 'Do Until oExec.StdOut.AtEndOfStream > > sReadLine = oExec.StdOut.ReadLine()' > > > > functionality? > > Don't have the time to try out the DOS part right now. > > You're looking to just capture what's going on like a logfile? > > Might start-transcript/stop-transcript work for you? > > Marco > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Executing batch files in PS scripts "David" wrote: > I can get the make batch file to run and pipe 'y' into it, but can't get the > parameters passed into it. > > echo y | make.bat "CODE 123 VER 1.2.3 2>&1" >build.log > I've solved part of this problem by not quoting the parameters for make.bat and specifing the path for the make.bat echo y | ./make.bat CODE 123 VER 1.2.3 2>&1 >build.log |
My System Specs![]() |
| | #5 (permalink) |
| | RE: Executing batch files in PS scripts > "y" | ./make.bat CODE 123 VER 1.2.3 2>&1 >build.log This appears to function properly but whenever make.bat outputs to stderr, powershell outputs the following after make.bat's warning messages; At C:\PowerShell\make.ps1:22 char:20 + "y" | ./make.bat <<<< CODE 123 VER 1.2.3 2>&1 >build.log It looks like powershell is trying to parse the commandline, but make.bat is using the commandline parameters properly. |
My System Specs![]() |
| | #6 (permalink) |
| | RE: Executing batch files in PS scripts I couldn't get PowerShell to directly process the batch file without parsing errors with the batch file parameters. I was able to pass the command line to cmd.exe without errors. cmd /c "echo y | makeall.bat CODE 123 VER 1.2.3 2>&1" > "build.log" Further processing of the output checking for success by piping the output into a function looking for a string. function TestSuccess ($success) { while ($input.movenext()) { if ($input.Current -match $success) { $global:Complete = $true } } } $global:Complete=$false cmd /c "echo y | makeall.bat CODE 123 VER 1.2.3 2>&1" | Tee-Object "build.log" | TestSuccess "MAKE successfully completed." |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| executing scripts within a web browser control under the system ac | .NET General | |||
| Executing PowerShell Scripts with IIS | PowerShell | |||
| executing powershell scripts on server | PowerShell | |||
| executing scripts async on remote hosts | PowerShell | |||
| Executing scripts in the current directory | PowerShell | |||