Call Unix Script from PeopleCode

Your rating: None Average: 4 (8 votes)

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();

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
Guest's picture
Guest (not verified)
Component properties stored in which metadata table

Through application designer when I open existing Component and right click on the component name I see Component properties.
Further On selecting internet tab,Toolbar details. Which tables keeps information about the toolbar actions Like Save , Cancel, Return to list etc for a component.

Lepa's picture
User offline. Last seen 4 weeks 14 hours ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Component properties stored in which metadata table

Your question is unrelated to this post. I will still give you a hit but please post questions related to the topic you're commenting on.

Have you looked at this post? You need to look at table PSPNLGRPDEFN, the values are stored as a number under column TBARBTN (I think). To test this, query a component, right down the number, change the properties save and then query it again. Compare the two results and you'll see which field has changed.

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Jonathan's picture
Jonathan (not verified)
Re: Call Unix Script from PeopleCode

Great code, this works perfect for me in DEV.

The UNIX script I wrote is getting a file from an external web site, and putting it on the Unix Box, so my A/E can open it and process the data. However, the script I wrote is currently hard coded with the /psoft/csdev/custom/ directory. Is there a way to pass a PS_HOME directory to the Unix script? Ideally, I'd like "&ps_home/custom" so I wouldn't have to recode this script when it goes from dev to test to qa to production.

Thanks!

Lepa's picture
User offline. Last seen 4 weeks 14 hours ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Call Unix Script from PeopleCode

Hey Jonathan,

your PS_HOME might be something like this:
PS_HOME=/psoft/$ORACLE_SID where $ORACLE_SID is csdev in dev and will change according to your environment. If $ORACLE_SID is not set up on the server side then get it from your PeopleCode. It should be the last part of your ps_home (you need to do the substring) and then pass it to the script.

&PS_HOME = LTrim(RTrim(GetEnv("PS_HOME"), "/"), "/");

 &exitCode = Exec(&PS_HOME | "path/to/script/scriptname " | &oracle_sid, %Exec_Synchronous + %FilePath_Absolute);

In your script, receive the value as such:
OracleSID=$3
if [ "$ORACLE_SID" = "" ]
then
  ORACLE_SID=$3
fi

Please use the forum if you want to discuss this more :)

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Gauri's picture
Gauri (not verified)
Re: Call Unix Script from PeopleCode

Hi

I am trying to execute this command but my script is not getting executed giving a return code of -1
when i execute my script on unix shell using command ksh : ksh testscript.ksh it works wells.

Guest's picture
Guest
Re: Call Unix Script from PeopleCode

I am also facing the same problem.

Post new comment

CAPTCHA
The question below is to prevent automated spam submissions.
5 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.