![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Exec Method Puzzle Below is a stripped down version of a script I've been working on. It works as expected when invoked with cscript.exe: It executes the nominated batch file: Set oFSO = CreateObject("Scripting.FileSystemObject") Set oWshShell = CreateObject("WScript.Shell") sTemp = oWshShell.ExpandEnvironmentStrings("%Temp%\TempBat.bat") Set oBatchFile = oFSO.CreateTextFile(sTemp, True) oBatchFile.WriteLine "echo %date% %time% >> c:\test.txt" oBatchFile.Close Set oExec = oWshShell.exec(sTemp) WScript.Sleep 1000 If I remove the Sleep method at the end then the script does not appear to do anything. It runs but it does not generate an entry in the log file. The real batch file contains several meaningful commands - none of them are executed. Could someone explain what difference the Sleep method makes? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Exec Method Puzzle On Jul 16, 9:40*am, "Pegasus [MVP]" <n...@xxxxxx> wrote: Quote: > Below is a stripped down version of a script I've been working on. It works > as expected when invoked with cscript.exe: It executes the nominated batch > file: > > Set oFSO = CreateObject("Scripting.FileSystemObject") > Set oWshShell = CreateObject("WScript.Shell") > sTemp = oWshShell.ExpandEnvironmentStrings("%Temp%\TempBat.bat") > Set oBatchFile = oFSO.CreateTextFile(sTemp, True) > oBatchFile.WriteLine "echo %date% %time% >> c:\test.txt" > oBatchFile.Close > Set oExec = oWshShell.exec(sTemp) > WScript.Sleep 1000 > > If I remove the Sleep method at the end then the script does not appear to > do anything. It runs but it does not generate an entry in the log file. The > real batch file contains several meaningful commands - none of them are > executed. > > Could someone explain what difference the Sleep method makes? object) before the underlying batch procedure can complete its execution. Note that the documentation illustrates the need to wait until the Status property becomes 1. Therefore, a proper implementation would be something like this ... Set oFSO = CreateObject("Scripting.FileSystemObject") Set oWshShell = CreateObject("WScript.Shell") sTemp = oWshShell.ExpandEnvironmentStrings("%Temp%\TempBat.bat") Set oBatchFile = oFSO.CreateTextFile(sTemp, True) oBatchFile.WriteLine "echo %date% %time% >> c:\test.txt" oBatchFile.Close Set oExec = oWshShell.exec(sTemp) Do Until oExec.Status <> 0 WScript.Sleep 50 Loop Tom Lavedas *********** |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Exec Method Puzzle "Tom Lavedas" <tglbatch@xxxxxx> wrote in message news:70b00bbe-7e36-416d-a8fa-4ab87724d11f@xxxxxx On Jul 16, 9:40 am, "Pegasus [MVP]" <n...@xxxxxx> wrote: Quote: > Below is a stripped down version of a script I've been working on. It > works > as expected when invoked with cscript.exe: It executes the nominated batch > file: > > Set oFSO = CreateObject("Scripting.FileSystemObject") > Set oWshShell = CreateObject("WScript.Shell") > sTemp = oWshShell.ExpandEnvironmentStrings("%Temp%\TempBat.bat") > Set oBatchFile = oFSO.CreateTextFile(sTemp, True) > oBatchFile.WriteLine "echo %date% %time% >> c:\test.txt" > oBatchFile.Close > Set oExec = oWshShell.exec(sTemp) > WScript.Sleep 1000 > > If I remove the Sleep method at the end then the script does not appear to > do anything. It runs but it does not generate an entry in the log file. > The > real batch file contains several meaningful commands - none of them are > executed. > > Could someone explain what difference the Sleep method makes? object) before the underlying batch procedure can complete its execution. Note that the documentation illustrates the need to wait until the Status property becomes 1. Therefore, a proper implementation would be something like this ... Set oFSO = CreateObject("Scripting.FileSystemObject") Set oWshShell = CreateObject("WScript.Shell") sTemp = oWshShell.ExpandEnvironmentStrings("%Temp%\TempBat.bat") Set oBatchFile = oFSO.CreateTextFile(sTemp, True) oBatchFile.WriteLine "echo %date% %time% >> c:\test.txt" oBatchFile.Close Set oExec = oWshShell.exec(sTemp) Do Until oExec.Status <> 0 WScript.Sleep 50 Loop Tom Lavedas *********** Thanks for your prompt reply. The documentation in script56.chm does illustrate the wait loop but unfortunately it never explains the reason for its existence. Your response makes it clear why the loop must be there. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Exec Method Puzzle On Jul 16, 11:56*am, "Pegasus [MVP]" <n...@xxxxxx> wrote: Quote: > "Tom Lavedas" <tglba...@xxxxxx> wrote in message > > news:70b00bbe-7e36-416d-a8fa-4ab87724d11f@xxxxxx > On Jul 16, 9:40 am, "Pegasus [MVP]" <n...@xxxxxx> wrote: > Quote: > > Thanks for your prompt reply. The documentation in script56.chm does > illustrate the wait loop but unfortunately it never explains the reason for > its existence. Your response makes it clear why the loop must be there. Glad I could help. Tom Lavedas |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Exec Method Puzzle It's often the case that things are better after a good sleep ![]() -- Joe Fawcett (MVP - XML) http://joe.fawcett.name "Pegasus [MVP]" <news@xxxxxx> wrote in message news:OumV5rhBKHA.4608@xxxxxx Quote: > Below is a stripped down version of a script I've been working on. It > works as expected when invoked with cscript.exe: It executes the nominated > batch file: > > Set oFSO = CreateObject("Scripting.FileSystemObject") > Set oWshShell = CreateObject("WScript.Shell") > sTemp = oWshShell.ExpandEnvironmentStrings("%Temp%\TempBat.bat") > Set oBatchFile = oFSO.CreateTextFile(sTemp, True) > oBatchFile.WriteLine "echo %date% %time% >> c:\test.txt" > oBatchFile.Close > Set oExec = oWshShell.exec(sTemp) > WScript.Sleep 1000 > > If I remove the Sleep method at the end then the script does not appear to > do anything. It runs but it does not generate an entry in the log file. > The real batch file contains several meaningful commands - none of them > are executed. > > Could someone explain what difference the Sleep method makes? > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Exec Method Puzzle "Joe Fawcett" <joefawcett@xxxxxx> wrote in message news:uRr1dFsBKHA.4792@xxxxxx Quote: > It's often the case that things are better after a good sleep ![]() |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Passing "| find" in command executed with EXEC method does not work | VB Script | |||
| Puzzle | Vista music pictures video | |||
| Method invocation failed because [System.String] doesn't contain a method | PowerShell | |||
| Can't exec a program from another | Vista security | |||
| Fun Puzzle? | Vista mail | |||