PDA

View Full Version : how to get error or informations from a exe under dos?



raphaelf
18th June 2008, 13:21
Hi Everybody,

i am using a small dos program to push a software to clients and its working great.

But i would like to get errors or information from this exe..

If i run this exe under dos i get for example host not found or copy complete..

How could i get this messages and put for example in a messagebox? :o

With this script i start my program in hide modus:


QString zeichen2 = "\"";
QString exePath2 = "psexec.exe";
QString arguments2 = "\\\\" + hostname + " -u " + username + " -p " + password + " -c -d -e -f -i -n 6 " + zeichen2 + path + "\\" + software + zeichen2;
#ifdef Q_OS_WIN32
ShellExecuteW(NULL, NULL, (LPCWSTR)exePath2.toStdWString().data(), (LPCWSTR)arguments2.toStdWString().data(), NULL, SW_HIDE);
#endif

Please help me :crying:

lunatike
18th June 2008, 13:31
To use messageBox you'll have to use QtGui.
You want DOS, so i suggest yout to use qWarning, qDebug methods...
However, if you want your executed exe to show more informations, u'll have to modify sources...

I'm not quite sure that I answered you ^^

Lele
18th June 2008, 13:37
Use QProcess, and connect a slot to readyReadStandardOutput().
You can then parse the output and whatever you need.

raphaelf
18th June 2008, 13:55
Hi, but if i use QProcess, im not able to run my exe in hide modus..

Its not possible to use my script, but to get messages from this exe? :crying:

jpn
18th June 2008, 14:52
Did you read what MSDN has to say about ShellExecute(), ShellExecuteEx() and co?

raphaelf
18th June 2008, 15:27
if i have understand with the function ShellExecute() will be not possible to get messages from my exe

With the function ShellExecuteEx() its only possible to get this informations:
ERROR_FILE_NOT_FOUND
ERROR_PATH_NOT_FOUND
but not from my exe :crying:

Should i change my strategy? And no use ShellExecute? :o

jpn
18th June 2008, 15:52
Well, I'm not really a WinAPI expert but just by taking a quick look at ShellExecute() documentation I can say that CreateProcess() and GetExitCodeProcess() might be a very good alternative for you since you are not really performing an abstract operation on a file in the sense that you want to let the explorer to choose a suitable application to do that, but you rather want to start a process with that specific application.

raphaelf
19th June 2008, 13:27
Hi,

if i have understand with CreateProcess Funktion im not able to run my tool in hide modus :(

You mean that i could use GetExitCodeProcess() to get information from my exe by using my code?

U mean it will work?

I am new and it would be great if i could find a example :crying:

jpn
19th June 2008, 15:30
if i have understand with CreateProcess Funktion im not able to run my tool in hide modus :(
Back to reading MSDN... CreateProcess() takes a "startup info" structure. You can pass SW_HIDE within that structure.


You mean that i could use GetExitCodeProcess() to get information from my exe by using my code?
Whose code if not yours? Once again, lookup the MSDN...! It is clearly explained there what this function does.


If the process has not terminted and the function succeeds, the status returned is STILL_ACTIVE. If the process has terminated and the function succeeds, the status returned is one of the following values:


The exit value specified in the ExitProcess or TerminateProcess function.
The return value from the main or WinMain function of the process.
The exception value for an unhandled exception that caused the process to terminate.



U mean it will work?
I haven't tried it and I'm not even going to. I'm just giving you some hints. You should try it.


I am new and it would be great if i could find a example :crying:
First of all, focus on reading the function and parameter descriptions from MSDN. Also make sure to follow links to structure descriptions of complex parameters. If still in doubt, doing a Google search on the function name might give surprising results...

raphaelf
20th June 2008, 10:17
Hi JPN,

i changed my strategy..

i will read information from dos and put it in a file. After i will put this informations to a messagebox for example..

Thank u :)