Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
IPL within a CGI
tik
I have a DCT/DCR and am using a cgi-callout. In this cgi that I am writing, I want to use a CLT to do xml validation and getting the results of this CLT into a variable $results and consequently $resultsfile.
I am trying to run the CLT like this:
my $results = `$my_cmd > $resultsfile`;
where $my_cmd = TeamSite::Config::iwgethome() . "/bin/iwxml_validate.ipl";
Then I am opening the file and printing it into $results, like:
open (RESULTS, "<$resultsfile");
while (<RESULTS>)
{
$results .= $_;
}
close RESULTS;
My problem is that I am not getting anything in $results or even the file $resultsfile, even though a blank file is being created.
Please suggest if i am using the CLT correctly witin my CGI.
Find more posts tagged with
Comments
Migrateduser
I
think
I understand what you're trying to do, but a much more straight-forward way to do this is by not outputting to a file at all. Instead, capture the output in the following way:
my $results = `$my_cmd 2>&1`;
This one line seems to do everything that you're trying to accomplish in that small block. Like I said, my understanding might be off, so if I am, what output are you anticipating, anyway?
Dave
Current Environment(s):
(1) TS 6.1 SP2 on W2K3
(2) TS 6.1 SP2 on W2K
nipper
my $results = `$my_cmd 2>&1`;
This syntax is shell dependent. If the user who is running this command
(root, iwui, etc) has ksh as their standard shell, it will work. However if this
is a csh/bash/tcsh shop that will fail. You see a very cryptic error, Invalid Output Redirect
when this is the wrong shell
If you have Unix Power Tools, it has a section of shell specific IO redirections. If you do not,
go buy it.
Same thing happens with some of the IW startup scripts, if IWUI has csh as the shell, TS will not start.
HTH
Andy
Migrateduser
Okay... but in those other shells, though, what were to happen if we just had:
my $results = `$my_cmd`;
?
I know it wouldn't trap any errors, but wouldn't it capture the STDOUT that tik is looking for?
Dave
Current Environment(s):
(1) TS 6.1 SP2 on W2K3
(2) TS 6.1 SP2 on W2K
nipper
Yes that should capture STDOUT but not STDERR. Depends on how that program was written
on whether the info will be there or not.
Andy
Adam Stoller
Uhm - I don't think it matters which shell you have defined for the user -- Perl will use 'sh' internally (I believe):
~ >
id
uid=301(fish) gid=10a(staff)
~ >
grep fish /etc/passwd
fish:x:301:10::/export/home/fish:/usr/local/bin/tcsh
~ >
iwperl -le 'my $x = qx(/bin/ls /dkdk); print "=" x 10 . "\n$x\n" . "=" x 10;'
/dkdk: No such file or directory
==========
==========
~ >
iwperl -le 'my $x = qx(/bin/ls /dkdk 2>&1); print "=" x 10 . "\n$x\n" . "=" x 10;'
==========
/dkdk: No such file or directory
==========
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
chuckles
Your syntax should work (although ghoti's suggestion is more concise). I suggest you print out the command line to your output as well as the current user ID and then try running it yourself. If it works or fails in a terminal window, then you have at least narrowed down the source of the problem.
nipper
I checked and my problem was with a .sh script, not a perl script.
/bin/su $iwui_user -c "$ULIMIT nohup $TOMCAT_HOME/bin/servletd $ARG" 1>>$SERVLETDLOGFILE 2>&1
In this case if $iwui_user has a csh flavored shell it breaks.
Andy