Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run external exe

Status
Not open for further replies.

fluppe689

Programmer
Jul 11, 2008
75
BE
Hello Guys,

I am pretty busy this days with new things.
Someone made for me a program call test.exe
I can of course run with with run c:test.exe
Problem : that program returns a 0 or something else
how can i test this.
When he return value = 0 program was run perfect else program did fail

wfg

Filip
 
Someone made for me a program call test.exe

My suggestion would be to have that 'someone' modify the EXE to also write the results to some file that you can programatically examine.

Or, if the EXE were created in VFP, modify it yourself to RETURN a value to somewhere that your calling program can examine.

Good Luck,
JRB-Bldr
 
Depends on how this return value is meant. There is one way o find out via GetExitCodeProcess. You need a process handle for that, CreateProcess and WaitForSingleObject will help with that.

In this case news2news has lots of examples, but there also is a KB article almost matching your need:

The only other thing you need after detecting the called process has stopped is GetExitCodeProcess:
DECLARE INTEGER GetExitCodeProcess in kernel32.dll INTEGER hProcess, INTEGER @nExitCode

Local lnExitcode
lnExitcode = 0
GetExitCodeProcess(hProcess, @lnExitCode)
? lnExitcode

Processhandle hProcess is what gets set from the KB code.

You can even test the process exiting with a return valu with a vfp.exe, as you can use the function ExitProcess in VFP to also return an exit code to your callee:

Declare Integer ExitProcess in kernel32.dll Integer nExitcode
ExitProcess(3)

Will exit your foxpro app comparable to QUIT or running to the end of main after CLEAR EVENT, but with an exit value of 3 instead of none. So you can do the same with foxpro.

Bye, Olaf.
 
Hello Experts,

First the programs runs a exe to update records in a pervasive database.

The way I run the external exe is like this

oWsh = CREATEOBJECT("wscript.shell")
oWsh.Run("apimport.exe", 2, .T.)
oWsh = .NULL.

this works but ...

If the run is good it returns a zero otherwise it returns a pervasive error code.

Is there way to catch that return code ???


wfg,


Filip
 
"If the run is good it returns a zero otherwise it returns a pervasive error code."

Where does this external program return the error code to?

If the code was written to something your primary application could interrogate (such as a text or log file, a data table, etc.) , everything would be fine.

Unless Olaf's suggestion above works - if the completion code is merely written to the console - you might be out of luck.

Perhaps you could get some suggestions from running a Google search for: wscript return value
One Google 'find' that I thought might be useful would be:
BUT it still depends on how the 'external' application is handling the completion code.

That is why I suggested above - have that 'someone' modify the EXE to also write the results to some file that you can programatically examine.

Good Luck,
JRB-Bldr
 
Hello Olaf,

the results are written to a txt file when there is an error.
The txtfile shows something like this :

23/11/2011 16:52:06 Er is een fout opgetreden op rij: 3 bij firma: 2 tabel: ARTLEV artikelnr: 059100031GX status: 10
23/11/2011 16:52:06 OPGELET: De import werd niet volledig uitgevoerd.
Which means : there is an error on file ARTLEV with status 10 (pervasive status)
and the import as not completed done

wfg,

Filip
 
Filip,

I can't connect what you say to your problem. Does apimport.exe write to that text file as it's output? Then why your initial question? Don't you know how to read in a text file in foxpro? Look up FileToStr().

I thought you where talking about the typical way to return an exit code from an exe, and for that you would need GetExitCodeProcess(hProcess, @lnExitCode), and of course hProcess on top of that, which means you need all the other code starting the exe vie CreateProcess, etc. Or try WSH with the much simpler way of just receiving the return value.

But if he exe writes out a text file, FileToStr() and you have the file content in a string.

Bye, Olaf.
 
Hey Olaf,

It returns 2 ways :

First return code in this example it will return 10 (from the status)

Second way : if there is an error it returns a text file for more details.

The most easy way would be : after executing to have directly that 10 (or other pervasive error code)

wfg,

Filip
 
Did this work or not?

retval = oWSH.Run("apimport.exe", 2, .T.)
Messagebox("returnstatus is "+transform(retval))

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top