suppressing dos windows

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

suppressing dos windows

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by pillick >> Fri, 10 Jan 2003 2:48:10 GMT

My jade program relies on a couple of dos programs to do a bit of preprocessing before data can be loaded into it. But its annoying to use these programs as the command promt window pops up regularly now.

I think someone mentioned that you could use a bit of c++ trickery to hide that? Can anyone go into the detail of how this would be done?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: suppressing dos windows

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by allistar >> Fri, 10 Jan 2003 22:06:35 GMT

Hi Pillick,
If this preprocessing can be done on the server node then you could make a non-gui server application that executes the DOS application, if the database server is running as a service then you won't see anything pop up (this idea is no good if the processing is done on a client node).

An alternative, as you suggest, is to do this in C++. You could write a ...dll that executes the DOS command, something like this:

//the command would be passed into the dll as a char* (a String from Jade) char *fullCommand = (char*)malloc(MAX_PATH);
sprintf(fullCommand, "someApplication.exe -someParameter");
//++++++++++++++++++++++++++++++++++++++++++++++++++
//execute the command and redirect stdout and stderr
//++++++++++++++++++++++++++++++++++++++++++++++++++
SECURITY_ATTRIBUTES sa = {0};
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
HANDLE hPipeOutputRead = NULL;
HANDLE hPipeOutputWrite = NULL;
HANDLE hPipeInputRead = NULL;
HANDLE hPipeInputWrite = NULL;
BOOL bTest = 0;
DWORD dwNumberOfBytesRead=0;
CHAR szMsg[100];
CHAR szBuffer[1000];

sa.nLength = sizeof(sa);
sa.bInheritHandle=TRUE;
sa.lpSecurityDescriptor=NULL;

//Create pipe for standard output redirection
CreatePipe(&hPipeOutputRead, &hPipeOutputWrite, &sa, 0);
//Create pipe for standard input redirection
CreatePipe(&hPipeInputRead, &hPipeInputWrite, &sa, 0);
//Make child process use hPipeOutputWrite as standard out and make sure // it does not show on screen
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdInput = hPipeInputRead;
si.hStdOutput = hPipeOutputWrite;
si.hStdError = hPipeOutputWrite;

//spawn the application
CreateProcess(conspawn, fullCommand, NULL, NULL, true, 0, NULL, NULL , &si, &pi);
//now that handles have been inherited, close it to be safe.
//Don't want to read or write to them accidentally
CloseHandle(hPipeOutputWrite);
CloseHandle(hPipeInputRead);

This should work as an external function, you would pass into this the command for the application you want to run. Another bonus is that you can read from the input pipe to get the output of the application and then that can be passed back to Jade by causing an event (although that's a bit tricky in C++, you'll need to use the JOMAPI). You should at least read the input pipe to look for errors.

We use this methodolgy for executing jadloadb.exe from our automatic upgrading application (written in C++, but it shoul d work from Jade as well).

Hope this helps,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: suppressing dos windows

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by pillick >> Sun, 12 Jan 2003 21:26:03 GMT

would you be able to make the dll for this allistar?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: suppressing dos windows

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by allistar >> Mon, 13 Jan 2003 1:11:53 GMT
would you be able to make the dll for this allistar?

Hi Pillick,
I would like to help out with this but am quite busy at the moment,
I figure there would be a few hours work with this (coding and
testing). When I next get some spare time I may look at implementing
this and making it available to all Jade developers via my website (www.silvermoon.co.nz). Sorry for not being able to help immediately, jobs that put bread on the table get priority, and I have a backlog of them at the moment.

Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: suppressing dos windows

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by pillick >> Tue, 14 Jan 2003 0:26:00 GMT

fair enough =)

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: suppressing dos windows

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:19 pm

by cnwrwm1 >> Sat, 11 Jan 2003 22:06:29 GMT

If you are using JADE@Work Start (CardSchema) then you can use an existing unpublished method call defined on CnKarmaCntrl :

result := app.myCnKarmaCntrl.emShellExecute(1, "open", script.fileName, null, null, 0); // 0=Hide Window, use 1 for debug, result > 32 is handle

Cheers

Richard Mitchell


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests