I have a MFC application which uses CreateProcess and then, call GetExitCodeProcess to get the exit code. But GetExitCodeProcess returns 1 and it fail.
More detail about my application -
My application run two process first is bat file and after successful completion of first process I create second process which is vb script. Both run in automation environment. This script contains simply a message box.
My second process fail with error 1 return by GetExitCodeProcess().
When I run scripts in reverse order like first as vbscript and second as bat file, both executes successfully.
I am not able to understand why my VB script fail with error code 1?
Please help. Thanks in advance!
Jyoti
Thank you very much for looking at my query and trying to answer it.
I have resolved this issue, hence thought to share solution.
In my application I was executing vb script with 'cscript' as command line parameter.
When I changed that parameter to 'wscript', it prompt me message that the filename.vbs not exists.
Then I understand the process is executing but it does not get vb script file and hence the Process fail with GetExitCodeProcess as return value = 1
This problem was not understood because I was using cscript. Whereas,
'cscript' runs entirely in the command line and is ideal for non-interactive scripts.
And 'wscript' will popup Windows dialogue boxes for user interaction.
Hence when I use wscript I understood the root cause.
The solution for this issue is I have checked the vbscript file exists or not. It will go ahead only if the file exists, till that, application wait for creation of vbscript file.
As said in GetExitCodeProcess() return 1 when process is not yet finished GetExitCodeProcess returns a BOOL to signal success or failure. The process return code is returned in the second parameter to GetExitCodeProcess.
Related
I send SQL scripts to a company where the operators run my scripts in TOAD. They have Oracle 10g. I am not allowed to create stored procedures, and I can send one script every day. Because I work on several projects, which have independent scripts, I send the main script like this:
#a.sql;
#b.sql;
#c.sql;
The three external scripts (say projects scripts) may be short or long, may call other external scripts, may contain PL/SQL blocks.
Normally, all my project scripts run, and I can get their result tables. But sometimes, some of my scripts fail. If a.sql raises any error, my script stops and doesn't run b.sql and c.sql.
In the case of an error, I want to stop processing the current project's script only, and I want my main script to continue with the next project script. If b.sql fails, too, then I want to continue with c.sql.
I tried WHENEVER SQLERROR, but nor EXIT neither CONTINUE does this. EXIT stops my script, CONTINUE doesn't skip the remaining part of my erroneous script (wasting a lot of time). I tried EXCEPTION in a PL/SQL block, but I could not call any external project script there. Is it any solution for this?
I would like to have different behaviour if a Command is executed from console and when is executed by the scheduler. Is there a way to check this from the command handle() method?
This is not a duplicate of Detect if running from the command line in Laravel 5
In the "marked as duplicate" one, it's answered how to detect if the code is running from Console, but in my case both manually triggered and CRON executed are running from Console, so doesn't solve my problem.
I am using the following very very basic script in a .bat file to keep a node.js server running on a windows machine.
: loop
npm start
goto loop
: end
However, if the server goes down, it does not restart automatically.
I do know that there are preferable ways of keeping the node up and running (example), but I really want to focus on other parts of the code at the moment and keep on integrating with other partners there. Thus, I am really looking for a very very simple bat file that can restart the server when it goes down (on Windows). What can possibly be wrong with the above one that I have?
Probably (you will have to check it), npm is a batch file (.bat or .cmd).
When you invoke a batch file from another batch file, the execution is transfered to the called batch and does not return to the caller. In your case, your goto loop is never reached as npm will never return
You need to use call npm start, so the execution will continue in the caller when the called batch ends.
I'm running a simple/single vbscript in Windows Scheduler to perform 13 individual file exports from our SalesForce app. The script runs as expected. Depending upon network traffic, the 13 exports take 3-5 minutes total to complete.
My intent was to run these exports serially, but vbscript seems happy to run them in parallel. SalesForce accommodates with no issue or complaint.
Upon successful completion of the Export, I run a second vbscript to import these results into another application (via an msaccess function). This second vbscript also provides the desired result.
Question: Is there any way to programatically determine when the Export script has completed, to permit me to safely kick-off the Import script? Currently I have setup a 2nd Scheduler job to run the Import script 10 minutes after the separate Export script...but this could fail. I am looking to tie these two script more closely to one another.
Any suggestions?
Thanks!
There are a couple of options. If both scripts are running on the same system with the same permissions, you could have the first script actually kick off the second script whenever it's finished.
If the scripts require different permissions, or you need them to start from a task manager, have your first script start by looking for an existing file such as SCRIPT1.COMPLETE. If that file exists, have script1 delete the file and start processing. When script1 finishes it's processing, create that file. Then in script2, create a while loop that looks for SCRIPT1.COMPLETE. If the file is not there, hold off for a few seconds then try again. Don't exit the while loop until the complete file shows up. Have script2 delete the COMPLETE file when it finishes processing. I would recommend setting your "wait a while" function to at least 30 seconds or so, that way your script isn't just constantly checking.
I have been using the at command to schedule the task
ex: at 14:45 my.bat
and i am getting the o/p on the command prompt as
"JOB ID is added"
But this command is not getting fired on the time which i have scheduled..
Can anyone please help me.......
I suspect the issue is not that the BAT file is not executing at all, but rather either or both of i) individual commands within the BAT file are failing, or ii) the output isn't getting sent to the place you're looking for it. (Things get even weirder if anything in the batch file requests input, since a) by default batch files may not be able to interact with the "console" at all and b) the system is probably unattended anyway at the time the batch file executes.) If my suspicion is right, there is no one "fix-everything" but rather a whole bunch of small fixes ...and you have to hit every one of them.
Find out the needed password to actually login as 'admin' (rather than your usual user), open a DOS box, and try to run the batch file. There should be some sort of error message that you can see. Fix that problem. Then try again ...and fix the next problem. Keep correcting problems and trying again until finally everything works.