I want to run a dos command against set of files in a folder.
The command is working, however I cant get the script to wait till the dos command is finished and closed before continuing.
I tried a few different ways. This is the simplest.
Dim cmdCompress
Set cmdCompress = DOpus.Create.Command()
cmdCompress.SetSource(strFolder)
cmdCompress.AddFilesFromFolder(strFolder)
cmdCompress.SetType("msdos")
cmdCompress.SetModifier("filesonly")
cmdCompress.SetModifier("sync")
cmdCompress.RunCommand("sync:""" + sJpegRecompressPath + """ --method smallfry ""{file}"" ""{file}""")
'Do next thing after command is finished.
How do force the script to wait till RunCommand finishes and the windows closes?
If that doesn't work, what happens if you run the command from a Command Prompt? Does it return immediately there as well, or only once it has finished?
Hi leo thanks for the reply.
Changing to @sync: didn't help.
If I run from command prompt, it outputs while running, then return control when done.
Also I can see in the output when the above script is run, each file is processed one at a time. So the second file is processed after the first file is completed.
A simpler more complete example. Opening a DOS cmd, running a sleep, then showing a dopus dialog. The dialog appears before the CMD closes.
I didn't include the @sync: (though i did try it locally) before the command as I have multiple commands, I do have the sync modifier set.
Option Explicit
Function OnClick(ByRef clickData)
Dim wsh
Set wsh = CreateObject("WScript.Shell")
wsh.run "cmd.exe /c echo %time% && timeout 4 && echo %time%",1,true
dim dlg
Set dlg = DOpus.Dlg
dlg.message = "hi, done"
dlg.Show
End Function
I'd be surprised if an external exe could act upon the files in the Opus command object. Haven't tried it though. Is it so difficult to hand over the files to sJpegRecompressPath via command line parameter?
When you use DOpus commands like sync:"c:\myexe.exe" --method smallfry "{file}" "{file}". You are asking DOpus to generate the command for you. If you passed three files in to command object, then you see three lines executed. The external exe does not need to know about the {file} param it will never see it.
No, It's not difficult to do myself using WScript (good tip). However the DOpus command is cleaner, no need to looping the files.
My reading for the doco indicated this should work with the sync modifier. I'm keen to know if the code above should have worked? As that seems the point of the sync modifier.
At the moment DOS mode functions are always run asynchronously and never wait for completion. We'll change this in the next update; in the mean time, you can force it to wait by adding the @runbatch modifier to the end of the command, like this:
Dim cmdCompress
Set cmdCompress = DOpus.Create.Command()
cmdCompress.SetSource(strFolder)
cmdCompress.AddFilesFromFolder(strFolder)
cmdCompress.SetType("msdos")
cmdCompress.SetModifier("filesonly")
cmdCompress.AddLine("""" + sJpegRecompressPath + """ --method smallfry ""{file}"" ""{file}""")
cmdCompress.AddLine("@runbatch")
cmdCompress.Run
'Do next thing after command is finished.