Stopping an executable running if vbs loop if outside criteria is met - vbscript

I'm using a VBScript to write into a configuration file config.txt, then run an executable SomeName.exe with the configuration I set.
The excecutable is not mine, I cannot interact with it.
The result is written in another text file Result.txt.
In the end, it looks like this
Set objShell = CreateObject("WScript.Shell")
For MyParameter = mystart to myend
'here I overwrite conf.txt with MyParameter value
Rt = objShell.run(SomeName.exe, 1, True) '--> True means "wait until the end before processing"
Next
What I'd like to do is to check the result.txt file and, if it's ok, stop the .exe and resume the loop with next value of MyParameter.
I already know how to read the file and decide whether the result is good enough or not (basically I read the last line and compare it with something else, very easy stuff) with a second script.
What I don't know is how to make this two scripts work together.
For now the only way I have is to run manually my second script and make it check from time to time (with Sleep function) if the result is good. In that case, I use taskill /im "SomeName.exe". But it's quite ugly and I have to run it with an infinite loop since I don't know how long it will take to SomeName.exe to reach the result (it's a simulation, it can be very very long !).
Have you got any idea on how to do that ?
Thanks a lot in advance for any help you can give me,

Why use WaitOnReturn=True?
Change that to False and then add your script code loop that checks for final line right after it.

Related

golang is executing the certian code which it shuoldn't in if else (log checked)

All log in this area is not printed (showing inside it's not running). However the last line is execute anyway. I'm so frustrated and sad, totally had no idea. Many thanks if there's any idea on it.
if !reflect.DeepEqual(MachineNow.TCP_machine.Two_D_Dta_Old, twoD_new) {
//the situation should not be executed
log.Println("new to old updated") //all log is not printing (O)
fmt.Println("new", twoD_new[0][0])
fmt.Println("old", MachineNow.TCP_machine.Two_D_Dta_Old[0][0])
MachineNow.TCP_machine.Two_D_Dta_Old = twoD_new //this line is doing anyway (X)
}
Have you checked your “log” output and level?
Maybe you set the output level to be higher than “Println”, so it’s simply ignored.
Try to use debug to know if this runs into this code block or just your assumption.
One more thing to check is: that if you run it by unit test, you need to add the “-v” flag to show output.
Solution: I trasform the object into JSON format and assign to the object. I don't know why but this is the only way to avoid execute that line no matter what. I thought it was just a mistake, now seems that line was indeed executed for unknown reason. it was running windows x64.
new_json, _ := json.Marshal(twoD_new)
_ = json.Unmarshal([]byte(new_json), &MachineNow.TCP_machine.Two_D_Dta_Old)

SAS Enterprise Guide with VBScript. Looping through SAS programs get stuck

I'm facing a random problem. When executing SAS programs with VBScript and the SASEGObjectModel.Application.7.1, looping through CodeCollection get stuck sometimes, even if the program execution was succeeded (the final data bases are correctly created in our server). The script simple doesn't go to the next program of CodeCollection (the prompt executing the script still open... ad infinitum). The SAS program It happens is random, also the frequency. I'm going with something like this:
Dim oSasApp
Set oSasApp = CreateObject("SASEGObjectModel.Application.7.1")
oSasApp.SetActiveProfile("some-profile")
Dim oSasProj
Set oSasProj = oSasApp.Open("some-project.egp", "")
Dim oProgramList
Set oProgramList = oSasProj.CodeCollection
Dim programOrder
Set programOrder = ...here I assign the SAS programs order array reading from a .txt...
For Each program in programOrder
For Each sasProgram in oProgramList
If sasProgram.Name = program Then
sasProgram.Run
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
oSasProj.Close
oSasApp.Quit
The problem is not the Log saving, as the log txt file of the stucked program is also correctly created.
Any idea? Maybe problems in our SAS server? Should I declare some kind of options?
SAS Guide version: 7.15
Windows: 10
Tks
So... for people facing the same problem. As I commented above, if I press enter on prompt the script flows again. So it is waiting for my input, for reasons I can't tell. I did 2 things to get around it. Not sure if all of them are necessary or if only one solves it, but here it goes:
First, by VBScript I turned off a list of generations and I applied a delay after the SAS program runs:
For Each program in programOrder
For Each sasProgram i oProgramList
If sasProgram.Name = program Then
sasProgram.GenSasReport = False
sasProgram.GenHTML = False
sasProgram.GenListing = False
sasProgram.GenPDF = False
sasProgram.GenRTF = False
sasProgram.Run
WScript.Sleep(2000)
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
Them, in my batch file, wich I use to call the VBScript with the "cscript" command, I set it to apply "y" to every single message the VBScript could ask:
cd ./script-folder
echo y | cscript script-file-name.vbs
And that is it.

Cannot convert Group Description to String Variable

I have the following code:
Set objHoldGroup = GetObject("LDAP://" & objGroup)
strGroupDesc = (objHoldGroup.Description)
WScript.Echo(strGroupDesc)
The variable strGroupDesc returns nothing when echoed. I can output the description directly but I need it for further processing. Thoughts?
Explanation: Apparently your script sets Option Explicit (good), which you didn't tell us about (bad). This option makes defining variables before you can use them mandatory (good). Normally that would raise an "undefined variable" error, though. Since that doesn't seem to happen with your code, you seem to also have an On Error Resume Next somewhere in your code (very bad), which, again, you chose to keep quiet about (bad).
Next time please don't omit parts of your code that are vital for troubleshooting the problem. And don't use On Error Resume Next.
Issue found: I forgot to Dim strGroupDesc.

Can anyone see what is wrong with my code?

My code is as follows:
a=msgbox("Do you like waffles",4+16,"Waffles")
Do While a=vbno
a
Loop
if a=vbyes then
b=msgbox("Do you like pancakes",4+16,"Pancakes")
Do While b=vbno
b
loop
if b=vbye then
c=msgbox("Do you like French toast",4+16,"French toast")
Do While c=vbno
c
Loop
else
d-msgbox("good",0+16,"YAY!")
end if
I know it is basic, but it comes up with the error message: "Error: Expected 'End'"
But as you can see 'end' is at the start of line 17, if it is something I haven't seen some where else in the code that might be causing this. I'm kind of new to this language and was putting things I knew how to do into a semi-useful paten.
I saved it as a .bat file and ran it using cmd.
Here is the original code posted in the question (as I'm writing this):
a=msgbox("Do you like waffles",4+16,"Waffles")
Do While a=vbno
a
Loop
if a=vbyes then
b=msgbox("Do you like pancakes",4+16,"Pancakes")
Do While b=vbno
b
loop
if b=vbye then
c=msgbox("Do you like French toast",4+16,"French toast")
Do While c=vbno
c
Loop
else
d-msgbox("good",0+16,"YAY!")
end if
A main error cause seems to be a notion that one can assign a definition to a variable. Well one can, but not in that way. Here is corrected code:
option explicit
dim answer
do
answer = msgbox("Do you like waffles",4+16,"Waffles")
if answer = vbYes then exit do
answer = msgbox("Do you like pancakes",4+16,"Pancakes")
if answer = vbYes then exit do
answer = msgbox("Do you like French toast",4+16,"French toast")
if answer = vbYes then exit do
loop
call msgbox( "good",0+16,"YAY!" )
There are however umpteen zillion ways to prepare food, and so also with code, plus, it's not clear if the above is the intention, but I guess it's pretty close.
At any rate, it's code that works and that you can build further on
Note that VBScript documentation is now only available as a CHM compiled help file, called "script56.chm".
The VBScript documentation is both available as a handy CHM compiled help file, called "script56.chm", as well as online in the MSDN library.
Note: you need to save the source code as a .vbs file.

is there a way to stop the popping up of the md5.exe tool while it generates the hash for a file

i have written a program in vbscript for which i have used md5.exe to generate hash. since there are many files to which the hash has to be generated, the md5 hash repeatedly generates hash for each file one after the other. but while this process is in progress, i can see it popping out on the screen as it generates the hashes ( it does not pop out the hashes, the tool itself pops out on the screen repeatedly). i want to do something such that it stops popping out yet generate the hash for all the files. please help guys!
Generally, when running a command, youj can supress its output by directing it to a file, then deleting the file
md5.exe blahblah >null the >null being the critical part. Note however, that null doesn't directly it to a magical blackhole. It creates a file named null and prints the output there
This would supress the output. IF you posted some code, I could have told you how to do that there. but if you are running it as a shell exec, this should work
You can use the run method to supress the window.
Set WshShell = CreateObject("WScript.Shell")
cmd= "C:\Users\Administrator\desktop\experimenting\md5.exe"
'OR whatvere your whole command is
cmdRun = WshShell.Run(cmd,0,true);
Answer from here
Want to hide command prompt window in using WshShell.Exec method
(Upvote the guy if you find it useful)
Please note that you have tro use the output file to read. You cannot read the output from the shell anymore.

Resources