Home
TeamSite
Perl system() syntax help
gsumers22texas
can you confirm the syntax to use with Perl's system( ) function when you build your command string as a variable?
Have tried the following, and it just won't seem to excecute, though when I reproduce the same system( ) function with hardcoded values for all of the variables, it works fine- my debug print statements show all of the individual variables are set correctly
my $cmdx = "$iwgen $gentpl $gendcr $genfile";
system($cmdx);
system("$cmdx"); --> didn't execute either
everything in Perldoc seems to suggest this should work-
is this something very obvious I"m just not seeing?
thanks in advance for all help
Find more posts tagged with
Comments
akshathp
Are the switches "-t" and "-r" part of your "$gentpl" and "$gendcr" variables?
I mean as per the syntax it should be:
IW-HOME/bin/iwgen -t tplpath -r dcrpath filename
Hope this helps.
Akshat Pramod Sharma
Interwoven Inc.
Migrateduser
You said "it just won't seem to excecute". Are you getting any error message? Can you run your script from a command prompt?
Try testing the value of the variable $? after the call to system to see if perhaps iwgen is returning a non-zero return code.
You can also try calling system as follows:
system($iwgen $gentpl $gendcr $genfile);
but the result should not be any different if each variable has one argument.
Brinko Kobrin
Interwoven Staff Engineer
Adam Stoller
As Akshat aluded to - why don't you print the value of $cmdx into a file so that you can see the full command as it looks when it's being handed to system() - then try running the exact same command (cut/paste) from the command line and see if it works.
Sometimes the simple-debugging steps are the best...
--fish
(Interwoven, Curriculum Development)
gsumers22texas
I do print out the value of $cmdx, and have compared it to an alternate system () function that has the actual command typed out instead of using variables, and the values match (with the -t and -r flags as well, with correct spacing between everything)
Unfortunately, I can't paste the value into the command line, because the full value violates the 255 character limit imposed by Solaris (my sysadmin says there's no way to extend that limit) - we use a subbranch, and our data types and data categories have meaningful names (thus are kind of long)
my main question is where in system ( ) to use quotes (double, single, does it matter?) and where quotes aren't necessary? the example in unlock.ipl uses quotes, concat operators, etc, but that doesn't seem to work for me-
gsumers22texas
yes, they are, and I've also validated spacing between the flags and the paths
Adam Stoller
If the cut-and-paste violates the command line length limitations - then it will do so within the system() call as well - since that forks off a shell process which is goverened by the exact same limitations.
Is there any way to reduce the length of the commands (could you perhaps cut-n-paste the full command into a post here - for us to look at)?
--fish
(Interwoven, Curriculum Development)
james1
One way to shorten the command is the chdir() into the workarea directory (under the primary file system mount -- /iwmnt or Y
, and then run the iwgen command with relative paths.
-- James
Migrateduser
have you tried running something like:
system("$cmdx > /tmp/cmdx.log 2>&1");
to see what exactly is getting executed?
akshathp
IN one of my workflwo for a template I am using iwgen and it is working for both Windows & Solaris platform.
my $gen_command = "$iwgen -t $tpl -r $dcr $output_file";
my $result = qx|$gen_command|;
Value of iwgen = /usr/iw-home/bin/iwgen
Value of tpl = /iwmnt/default/main...(tpl path here)
Value of dcr = /iwmnt/default/main...(dcr path here)
Value of output_file = /default/main...(location of html here)
Hope this helps.
Akshat Pramod Sharma
Interwoven Inc.
gsumers22texas
we've resolved the issue, and it lay in the templating setup, not in our workflow- the problem was not with the syntax of the system ( ) function after all
it turned out to be due to a communication problem between developers- since I'd tested the templating components independently before testing my script, the name of the tpl was renamed, but templating.cfg entry wasn't updated to reflect the new tpl name
I think ghoti stated it most succinctly: sometimes the simplest debugging methods are the best - like looking behind you every once in a while and make sure we're you've come from hasn't been changed !!
many thanks still for all the suggestions, it's shown some alternative coding / methods to use that may still be useful in this and/or other areas
relevant code snippets:
my $area = $task->GetArea();
my $dcrpath =
@files[0]
;
($templateroot, $datacategory, $datatype, $subdir, $dcrname) = split(/\//, $dcrpath);
(not sure yet if we'll need all these values seperately or not)
my $gentpl = "-t $area/$templateroot/$datacategory/$datatype/presentation/$dcrname.tpl";
my $gendcr = "-r $area/$dcrpath";
my $genfile = "$area/DCFS/$dcrname.htm";
my $cmdx = "$iwgen $gentpl $gendcr $genfile";
system($cmdx);
Migrateduser
Thank you for giving us closure!
Looking over your code snippets, there are two pitfalls of which you should be aware.
1. In the following statement, you
assume
that there is exactly one directory under the datatype (no more, no less).
($templateroot, $datacategory, $datatype, $subdir, $dcrname) = split(/\//, $dcrpath);
2. In the following two statements you
assume
that there will not be any spaces in your paths.
my $gentpl = "-t $area/$templateroot/$datacategory/$datatype/presentation/$dcrname.tpl";
my $gendcr = "-r $area/$dcrpath";
Just a friendly FYI.
Brinko Kobrin
Interwoven Staff Engineer
Adam Stoller
Another pitfall:
my $dcrpath =
@
files[0];
the
@
indicates an array context - and thus you are getting a single
slice
of an array using this syntax. It should be:
my $dcrpath =
$
files[0];
Though it's possible this may be changing in Perl 6 (I've heard rumors, but haven't spent much time looking at it yet)
--fish
(Interwoven, Curriculum Development)
gsumers22texas
thanks for replies and fyis-
our code isn't quite ready to roll for all scenarios yet, just trying to get basic functionality working right now
#1 pitfall response- we actually aren't using the $subdir variable to populate the iwgen -t path value, we're assuming it'll actually be "presentation" due to the setup requirements of templating data types
# 2 pitfall response- there shouldn't be any spaces "between" the variables that are building the path, though spaces "within" the variables themselves should be acceptable - all of our data categories and data types are named without spacing in the names - but we'll make sure to test this in our testing
thanks again for the feedback-
gsumers22texas
hi ghoti-
isn't this required this way because that "
@files"
is what's being returned from WFtask GetFiles sub? how else to get files already attached to a given job?
Migrateduser
Both of these forms (
@files[0]
and $files[0]) reference the same variable (
@files)
.
The difference is that $files[0] refers to the first element of the list
@files
, and
@files[0]
refers to the sub-list ("slice") of elements 0 through 0.
In many cases the end result will be the same because Perl will try to convert the values to the appropriate types. But I believe that ghoti is right; the safest and most explicit way to reference the first file is $files[0].
Brinko Kobrin
Interwoven Staff Engineer