Running external programs

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

Running external programs

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

by pillick >> Tue, 16 Jul 2002 1:53:26 GMT

Hey,

The system I am using relies on two external programs to do a bit of preproccessing before my jade program can make use of the data.

At the moment these two programs are run from the command prompt, but I would like to change them so that they can be run within jade. Can jade be made to run programs exactly as you run them in the command prompt?

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

Re: Running external programs

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

by CarlRanson >> Tue, 16 Jul 2002 2:36:57 GMT

refer to: node.createExternalProcess

eg,

create args transient;
args.add('-d');
args.add('"'& archiveFile & '"');
args.add('"'& filesDirectory & '"');
result := node.createExternalProcess(
'',
winZipPath,
args,
'',
false,
false,
processResult);
delete args;

if you also need to do stuff with batch files, piping or other command line features, you can run "command.com" as your program.

CR

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

Re: Running external programs

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

by allistar >> Tue, 16 Jul 2002 2:48:29 GMT

Hi there,
If you maintain the source code for the external application is may also be easier to compile it as a dll and define external functions in your schema.

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: Running external programs

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

by pillick >> Wed, 17 Jul 2002 3:36:19 GMT

Umm, this is what I want to do for one of the programs:

automatically go into command prompt and run: D:\JadeMarket\Extraction\unpac C:\Data\DATA01.PAC

I wrote this jadescript to do that:

extract();

vars
pacFile, directory, command : String ;
args : StringArray ;
result, exitValue : Integer ;
begin
pacFile := "C:\Data\DATA01.PAC" ;
directory := "D:\JadeMarket\Extraction\" ;
command := "unpac" ;

create args transient ;
args[1] := pacFile ;
result := node.createExternalProcess(directory, command, args, "", false, true, exitValue) ;
write result ;
write exitValue ;
end;

but unfortunately it doesnt work: result is allways 3 and exitValue is allways 0. When I type the command above in the command prompt it works perfectly - the problem is getting jade to mimic that.

Any ideas on whats going wrong?

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

Re: Running external programs

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

by allistar >> Wed, 17 Jul 2002 3:43:54 GMT

Hi there,
try this:

directory := "D:\JadeMarket\Extraction";
command := directory & "\unpac c:\data\data01.pac";

result := node.createExternalProcess(directory, command, null,
command, false, false, exitValue);

Regards,
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: Running external programs

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

by CarlRanson >> Wed, 17 Jul 2002 3:51:12 GMT

I think you need to fully qualify the command. Is it an exe, com or bat file? It would also help to add the directory to it.
So the command is probably supposed to be:

command := "D:\JadeMarket\Extraction\unpac.exe" ;

Note that the directory parameter is the path to run the process in, not necessarily the path to the program to run (that can be included in the command parameter if necessary).

eg,
node.createExternalProcess('C:\myDir', 'c:\windows\system\foo.exe', args, "", false,true, exitValue)
runs the command "c:\windows\system\foo.exe" in directory "C:\myDir"

Hope that helps.
CR

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

Re: Running external programs

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

by pillick >> Wed, 17 Jul 2002 4:21:44 GMT

cheers, works perfectly now, only... ( >.< sorry for asking so many questions)... is there any way to suppress the command prompt window from showing? and will this show on the client if it is executed on the server?

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

Re: Running external programs

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

by CarlRanson >> Wed, 17 Jul 2002 5:21:16 GMT

Im not aware of any way to hide the window of the called program.

It will run on the same node that makes the call to createExternalProcess, ie the client node if running a client execution method, and the server node if running a server execution method.

Since there doesnt seem to be any way to run jade methods on the presentation client (only external methods), i dont think it would be visible to the users under thin client.

CR

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

Re: Running external programs

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

by allistar >> Thu, 18 Jul 2002 5:09:20 GMT

You can supress the output of an external command line application
with a little bit of C++ trickery. You would need to create a C++ dll that does a "CreateProcess" of your DOS application, and sets the "STARTUPINFO" and "PROCESS_INFORMATION" structures in a way that will suppress the command prompt window. Then you call that dll function as
an external function in Jade.
A nice side effect of this is that you can then get this to execute
on the client computer instead of the application server.

Regards,
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: Running external programs

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

by MITCHELL1 >> Mon, 22 Jul 2002 2:11:36 GMT

An alternative you could try, if you have JSM Start (CardSchema) is to use the external method call 'emCreateProcess' in karma.dll. If you run this with modal=true then you can also capture the standard out during the process execution. The method signature is

emCreateProcess( obj: Object;
cmdLine: String;
modal: Boolean;
notifyStdOut: Boolean;
childStdInText: String;
tag : Integer;
exitCode: Integer output): Integer is "emCreateProcess" in "karma";


1. Your karma.dll needs to be version 2.6.2.12 or later.

2. The 'tag' that is part of the emCreateProcess method signature is returned as part of the userNotification . The eventType that is caused by the dll is hard coded and has the value 9950. In the attached method file, you'll see that I have a global constant Process_Std_Out_Event. This has value 9950 and is what the application that is to receive the std out must subscribe to.

3. The notification itself (userInfo) is a Binary structure : the first four bytes are an Integer representing the eventTag that you supplied in the 'tag' parameter of the emCreateProcess call. This is optional and can be zero. The remaining bytes of the userInfo[5:end] are a string containing the std out.

4. Exit code only has a meaning when modal=true.

You need two apps to make this work : one is the 'ProcessLogger', which receives std out notifications from karma.dll, and the other is your main-line process which executes the emCreateProcess and normally blocks until the process ends.

App1 should

vars
proc : Process;
yourObj : YourObject;begin

beginTransientTransaction;
create yourObj sharedTransient; // I use a shared transient here, but a persistent object could also be used
commitTransientTransaction;
proc := app.startApplicationWithParameter(<schema>,<App2>, yourObj);
result := app.emCreateProcess(yourObj, commandline, true, true, null, Process_Std_Out_Event, exitCode);
if exitCode <> 0 then ..... // error handling

App2 in its initialisation method should

initialiseApp2(yourObj : YourObject);

vars
result : Integer;
exitCode : Integer;begin

self.beginNotification(yourObj, Process_Std_Out_Event, 0, 0);
end;

And in the userNotification event (on self i.e. app, in this example) you receive the std out in the userInfo part of the notification. Note that this comes in dribs and drabs and you'll need to search for CrLf if you want to get each line nicely formatted.

Hope this helps.


--
Richard W Mitchell
Senior Software Engineer
Systems Management Development Centre
Jade Software Corporation Ltd
mailto: rmitchell@jade.co.nz
Attachments
2342_1.mth
(2.63 KiB) Downloaded 174 times


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 13 guests