Call Unix Script from PeopleCode

A function to call UNIX and/or shell script from PeopleCode.


/*call unix script from PeopleCode*/
Function CallScript;

/*According to PeopleBooks, PS_HOME is always prefixed to the file location*/
&exitCode = Exec("/path/to/script/scriptname ", True);

End-Function;

The Exec command has changed in PT8.4x so the above function will be:


Function CallScript;

/*Use %Exec_Asynchronous if it is not important to wait for a response from the called script*/
&exitCode = Exec(&PS_HOME | "path/to/script/scriptname", %Exec_Synchronous + %FilePath_Absolute);

If &exitCode <> 0 Then
MessageBox(0, "", 0, 0, ("Script was not Successful! Exit code returned by script was " | &exitCode));
End-If;

End-Function;

If you are using the Exec call inside of an Application Engine and you are calling it in a Synchronous mode, make sure you commit your work before you call it, otherwise, you will get a run time error.


CommitWork();
CallScript();


You can review more about this document by using the following Google Search
Google

Related Posts by Categories



1 comment:

Unknown said...

Hi,

I am trying to use exec function to run a .sh file in an App Engine and the exit code value is not 0 which says it did not run successfully. Exit code value is 1. How can I know the reason for unsuccessful execution. What does exit code = 1 means ? Please help.

Thanks

Post a Comment