<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Invoking another PERL script within a PERL script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865365#M97113</link>
    <description>Hi, &lt;BR /&gt;couldn't resist to take up the thread.&lt;BR /&gt;&lt;BR /&gt;First listen to what procura posted, and run other Perl code by a do, or require statement.&lt;BR /&gt;Better yet, put reusable code bits in a Perl module (aka package within a file of same name ending with suffix .pm), and import it by either "use" or "require" (though require doesn't import anything into your namespace)&lt;BR /&gt;&lt;BR /&gt;Don't call external executables for which there exist Perl built-ins.&lt;BR /&gt;Perl has almost all of the Unix syscalls implemented as built-in functions.&lt;BR /&gt;The rest that isn't available immediately is covered most of the time by additional CPAN modules (which of course need prior installation).&lt;BR /&gt;&lt;BR /&gt;Find out about Perl's already built-in functions/syscalls by reading the respective POD (aka Plain Old Documentation).&lt;BR /&gt;Start for instance with &lt;BR /&gt;&lt;BR /&gt;perldoc perl&lt;BR /&gt;perldoc perlintro&lt;BR /&gt;perldoc perlsyn&lt;BR /&gt;perldoc perlop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To give you an example of a redundant externel executable you used,&lt;BR /&gt;the &lt;BR /&gt;&lt;BR /&gt;system "chmod $modbits $file_list_string";&lt;BR /&gt;&lt;BR /&gt;is wasteful (and can be perilious).&lt;BR /&gt;Better call Perl's built-in chmod().&lt;BR /&gt;Read about it's usage&lt;BR /&gt;&lt;BR /&gt;perldoc -f chmod&lt;BR /&gt;&lt;BR /&gt;Further, to access password data (or any of the other notorious Unix system data files), there are Perl namesakes of the libc functions&lt;BR /&gt;e.g. read their POD (someone mentioned them already)&lt;BR /&gt;&lt;BR /&gt;perldoc getpwnam&lt;BR /&gt;perldoc perlfunc&lt;BR /&gt;&lt;BR /&gt;Then read what is said in the POD of system() and exec().&lt;BR /&gt;&lt;BR /&gt;perldoc -f system&lt;BR /&gt;perldoc -f exec&lt;BR /&gt;&lt;BR /&gt;especially what is said about the possible  interaction of these calls with the shell, and the treatment of shell tokens and meta characters (viz.  single string argument vs. list of args)&lt;BR /&gt;&lt;BR /&gt;There it also says that in order to get the real return code of an externally called executable you have to right shift the return value of system() by 8 bits.&lt;BR /&gt;&lt;BR /&gt;Beware, exec() never returns to your script.&lt;BR /&gt;So its usual usage is within the child's block after a fork.&lt;BR /&gt;&lt;BR /&gt;If you want to read from or write to an external program's output/input (or even both at the same time) use a fork() and exec()&lt;BR /&gt;&lt;BR /&gt;perldoc perlipc&lt;BR /&gt;&lt;BR /&gt;Finally, get used to check the successful execution of open(), &amp;lt;&amp;gt;, close() calls (be it regular files, pipes, sockets or whatever)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 17 Dec 2002 17:48:39 GMT</pubDate>
    <dc:creator>Ralph Grothe</dc:creator>
    <dc:date>2002-12-17T17:48:39Z</dc:date>
    <item>
      <title>Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865356#M97104</link>
      <description>HI,&lt;BR /&gt;&lt;BR /&gt;I have a PERL script which needs to be invoked within another PERL script. &lt;BR /&gt;&lt;BR /&gt;However, that PERL script(attached in this message) which needs to be invoked within a PERL script does not get invoked. &lt;BR /&gt;&lt;BR /&gt;The line which invokes the other PERL script is as follows:&lt;BR /&gt;system("/pgadm1/adm/ken_lee/grpmgr-FM/test/edgrp.pl");&lt;BR /&gt;&lt;BR /&gt;But this line did not call the PERL script edgrp.pl.&lt;BR /&gt;&lt;BR /&gt;I've also tried invoking the script above by:&lt;BR /&gt;`/pgadm1/adm/ken_lee/grpmgr-FM/test/edgrp.pl` in the script, but could not work.&lt;BR /&gt;Also, in the script attached, I tried accessing the user's passwd field from the NIS passwd entry by doing:&lt;BR /&gt;&lt;BR /&gt;@passwdEntry = `/usr/bin/ypmatch $grpLead passwd`;&lt;BR /&gt;for $j (@passwdEntry){&lt;BR /&gt;        chomp($j);&lt;BR /&gt;        @passwdField = split(/:/, $j);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;$passwd = $passwdField[1];&lt;BR /&gt;open (owner, "&amp;gt;/pgadm1/adm/cleaw/grpmgr-FM/test/ownerFile");&lt;BR /&gt;print owner "$grpLeader \n";&lt;BR /&gt;print owner "$passwdField \n";&lt;BR /&gt;close(owner);&lt;BR /&gt; &lt;BR /&gt;However, contents of /pgadm1/adm/cleaw/grpmgr-FM/test/ownerFile did not contain the variable $grpLeader.  &lt;BR /&gt;&lt;BR /&gt;Could someone kindly help me out on this matter? Any modifications made to the script is most welcome.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 01:06:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865356#M97104</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-12-17T01:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865357#M97105</link>
      <description>&lt;BR /&gt;Does the script run by itself?&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Tue, 17 Dec 2002 01:16:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865357#M97105</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-12-17T01:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865358#M97106</link>
      <description>Harry, &lt;BR /&gt;The script is also capable of running on its own without calling the other PERL script. &lt;BR /&gt;The same goes for the invoked PERL script.&lt;BR /&gt;&lt;BR /&gt;Any inputs on how I could solve this problem?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 02:15:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865358#M97106</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-12-17T02:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865359#M97107</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I would suggest trying to grab the return status from your system call in your script to see if the call is unsuccessful.  Something like this:&lt;BR /&gt;&lt;BR /&gt;$sys_status = system("/pgadm1/adm/ken_lee/grpmgr-FM/test/edgrp.pl"); &lt;BR /&gt;&lt;BR /&gt;print "After system call - status is $sys_status\n";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;That might give you a clue about what is happening with the system call.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 03:01:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865359#M97107</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2002-12-17T03:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865360#M97108</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;After looking at your script, I thought of one other thing.  According to your code you are creating the 'edgrp' file, chmod'ing it to be executable, trying to execute it, and then closing it:&lt;BR /&gt;&lt;BR /&gt;print edgrpFile "/usr/local/bin/edgrp add $userName $grpName \n";&lt;BR /&gt;system("chmod 755 /pgadm1/adm/cleaw/grpmgr-FM/test/editgrpFile");&lt;BR /&gt;system("/pgadm1/adm/cleaw/grpmgr-FM/test/editgrpFile");&lt;BR /&gt;close(edgrpFile);&lt;BR /&gt;&lt;BR /&gt;I'd try writing to the 'edgrp' file, closing it, and then chmod'ing it and executing it.  There might be a problem with executing it while it is still open as the contents of the file may not have been written out when you do your system call?&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 03:10:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865360#M97108</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2002-12-17T03:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865361#M97109</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I can confirm what I wrote in my last post.  I wrote a small Perl script that opens a file, prints a single line of text that does an echo command, and then tries to chmod the file and execute it.  Without closing the file, the system call to execute it returns a -1, but if I close the file first the system call is successful.&lt;BR /&gt;&lt;BR /&gt;open (edgrpFile,"&amp;gt;/home/users/jpoff/scripts/perl/runit");&lt;BR /&gt;print edgrpFile "echo \"Here we are in runit\"";&lt;BR /&gt;close(edgrpFile);&lt;BR /&gt;&lt;BR /&gt;$sys_status1 = system("chmod 755 /home/users/jpoff/scripts/perl/runit");&lt;BR /&gt;print "Returned from chmod system call with status of $sys_status1\n";&lt;BR /&gt;&lt;BR /&gt;$sys_status2 = system("/home/users/jpoff/scripts/perl/runit");&lt;BR /&gt;print "Returned from system call with status of $sys_status2\n";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now, if I comment out the close(edgrpFile); line, I get these results:&lt;BR /&gt;&lt;BR /&gt;Returned from chmod system call with status of 0&lt;BR /&gt;Returned from system call with status of -1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But with the close() in place:&lt;BR /&gt;&lt;BR /&gt;Returned from chmod system call with status of 0&lt;BR /&gt;Here we are in runit&lt;BR /&gt;Returned from system call with status of 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The trick is that Perl does not support unbuffered output.  Take a look at 'man perlfaq5' [I'm running Perl 5.8.0].  The beginning of that faq explains how Perl buffers output and a flag to force Perl to flush the buffers after every printf() or write(), but the easy and clean way to do it is to close the file before executing it.&lt;BR /&gt;&lt;BR /&gt;Thanks for making me learn something new today.  That was pretty cool!&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 03:41:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865361#M97109</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2002-12-17T03:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865362#M97110</link>
      <description>Why call another perl script with system ()? This is a shipload of unneeded overhead.&lt;BR /&gt;&lt;BR /&gt;use 'do "script";' instead. The parser will read the script and execute it.&lt;BR /&gt;&lt;BR /&gt;If you also want it to be executed only once, but to allow multiple calls (for which all suubsequent ones are ignored), use 'require "script";' which will `remember' that it has been loaded and run. In this mode, end your script with a `true' value, something like '1;'</description>
      <pubDate>Tue, 17 Dec 2002 09:35:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865362#M97110</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-12-17T09:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865363#M97111</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;It looks like the problem in your sample script is that you refer to the variable as $grpLead on the ypmatch line, and $grpLeader on the print statement.&lt;BR /&gt;&lt;BR /&gt;Also, I haven't tested it under HP-UX (works under most others), but perl has a built-in getpwnam() function, which under it's definition should follow the same rules (check NIS, /etc/passwd, etc) your system does in locating passwd entries.  That would cut 5 lines down to 1.&lt;BR /&gt;&lt;BR /&gt;-Scott-</description>
      <pubDate>Tue, 17 Dec 2002 14:12:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865363#M97111</guid>
      <dc:creator>Scott Corzine</dc:creator>
      <dc:date>2002-12-17T14:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865364#M97112</link>
      <description>Merijn is correct, if the script you are calling is a Perl script.  The do 'script' function handles it much better.  &lt;BR /&gt;&lt;BR /&gt;When I looked at the sample code the author supplied, I couldn't tell if the script being called was a Perl script or not, so I used the system call and made my example call a shell script, which won't work with the 'do' function.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 15:06:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865364#M97112</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2002-12-17T15:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking another PERL script within a PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865365#M97113</link>
      <description>Hi, &lt;BR /&gt;couldn't resist to take up the thread.&lt;BR /&gt;&lt;BR /&gt;First listen to what procura posted, and run other Perl code by a do, or require statement.&lt;BR /&gt;Better yet, put reusable code bits in a Perl module (aka package within a file of same name ending with suffix .pm), and import it by either "use" or "require" (though require doesn't import anything into your namespace)&lt;BR /&gt;&lt;BR /&gt;Don't call external executables for which there exist Perl built-ins.&lt;BR /&gt;Perl has almost all of the Unix syscalls implemented as built-in functions.&lt;BR /&gt;The rest that isn't available immediately is covered most of the time by additional CPAN modules (which of course need prior installation).&lt;BR /&gt;&lt;BR /&gt;Find out about Perl's already built-in functions/syscalls by reading the respective POD (aka Plain Old Documentation).&lt;BR /&gt;Start for instance with &lt;BR /&gt;&lt;BR /&gt;perldoc perl&lt;BR /&gt;perldoc perlintro&lt;BR /&gt;perldoc perlsyn&lt;BR /&gt;perldoc perlop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To give you an example of a redundant externel executable you used,&lt;BR /&gt;the &lt;BR /&gt;&lt;BR /&gt;system "chmod $modbits $file_list_string";&lt;BR /&gt;&lt;BR /&gt;is wasteful (and can be perilious).&lt;BR /&gt;Better call Perl's built-in chmod().&lt;BR /&gt;Read about it's usage&lt;BR /&gt;&lt;BR /&gt;perldoc -f chmod&lt;BR /&gt;&lt;BR /&gt;Further, to access password data (or any of the other notorious Unix system data files), there are Perl namesakes of the libc functions&lt;BR /&gt;e.g. read their POD (someone mentioned them already)&lt;BR /&gt;&lt;BR /&gt;perldoc getpwnam&lt;BR /&gt;perldoc perlfunc&lt;BR /&gt;&lt;BR /&gt;Then read what is said in the POD of system() and exec().&lt;BR /&gt;&lt;BR /&gt;perldoc -f system&lt;BR /&gt;perldoc -f exec&lt;BR /&gt;&lt;BR /&gt;especially what is said about the possible  interaction of these calls with the shell, and the treatment of shell tokens and meta characters (viz.  single string argument vs. list of args)&lt;BR /&gt;&lt;BR /&gt;There it also says that in order to get the real return code of an externally called executable you have to right shift the return value of system() by 8 bits.&lt;BR /&gt;&lt;BR /&gt;Beware, exec() never returns to your script.&lt;BR /&gt;So its usual usage is within the child's block after a fork.&lt;BR /&gt;&lt;BR /&gt;If you want to read from or write to an external program's output/input (or even both at the same time) use a fork() and exec()&lt;BR /&gt;&lt;BR /&gt;perldoc perlipc&lt;BR /&gt;&lt;BR /&gt;Finally, get used to check the successful execution of open(), &amp;lt;&amp;gt;, close() calls (be it regular files, pipes, sockets or whatever)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2002 17:48:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invoking-another-perl-script-within-a-perl-script/m-p/2865365#M97113</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-12-17T17:48:39Z</dc:date>
    </item>
  </channel>
</rss>

