SteveC has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Unable to get a tcshell command line working in PERL v5 system command
  • Download Code

Replies are listed 'Best First'.
Re: Unable to get a tcshell command line working in PERL v5 system command
by Corion (Patriarch) on Jul 13, 2007 at 12:22 UTC

    You don't show us your Perl code, so it's hard to give you concrete advice. Most likely, some quoting is messing your strings up - I recommend a here-document to circumvent all those ugly quotes:

    my $shell_code = <<'SHELL'; cleartool lsvob -short | \ sort | \ sed 's/.*/test -d "&\/." \&\& echoexec cleartool find & -versi +on \ +"lbtype(LABEL1) \&\& !lbtype(LABEL2)\" -print /' | \ sh SHELL warn "Running >>$shell_code<<"; system($shell_code) == 0 or die "Couldn't launch >>$shell_code<<: $! / $?";

    I'm also not sure about the weirdo quoting going on - I think many of these commands are better done within Perl, but that's hard to say because I don't know what they are supposed to do.

Re: Unable to get a tcshell command line working in PERL v5 system command
by ikegami (Patriarch) on Jul 13, 2007 at 13:46 UTC

    You mention tcsh, but system uses sh no matter what the parent or default shell is. You can bypass sh by using the system LIST form to run tcsh explicitly.

    my $cmd_for_tcsh = 'cleartool ...'; system('tcsh', '-c', $cmd_for_tcsh);
Re: Unable to get a tcshell command line working in PERL v5 system command
by sgt (Deacon) on Jul 13, 2007 at 14:36 UTC

    Well I would do the following:

  • put the shell lines in a script and assure that they work!
  • use the shell that perl is going to use, or call explicitly /bin/tcsh or whatever
  • once you have something working, if it is short just use the rule {cmd => sh -c 'cmd1', where cmd1 is cmd in which ' => '\''}

    @cmd = ( q{/bin/tcsh}, "-c", ...); system(@cmd) == 0 or warn;

    Also the construct 'echo-like "..." | sh' to send commands to the shell seems ugly, just use perl to generate the necessary shell script, and execute it

    A small example to make things clearer, I hope.

    % steph@ape (/home/stephan/t2) % % ls -1 bag'cmds driver.pl more cmds % steph@ape (/home/stephan/t2) % % cat $'bag\'cmds' echo just another shell hacker echo just another perl hacker % steph@ape (/home/stephan/t2) % % cat 'more cmds' echo .done % steph@ape (/home/stephan/t2) % % cat driver.pl #!/bin/perl use strict; use warnings; $|++; use Data::Dumper; # make this line after the q op. valid shell my $main_cmd = q{ cat bag\'cmds "more cmds" | sh }; my @cmd = ( '/bin/ksh', '-c', $main_cmd ); print Dumper(\@cmd); print "\n./bin/sh -c '/bin/ksh -c ...'\n"; system(@cmd) == 0 or warn; print "\n.directly: at the mercy of your system shell\n ->"; system('echo $0') == 0 or warn; print "\n"; system($main_cmd) == 0 or warn; print "\n.generating script\n"; my $cmd_file = qq{temp$$.sh}; open my $outh, '>', $cmd_file or die; print $outh <<"EOSHELL"; $main_cmd EOSHELL system('cat', '-evnt', $cmd_file) == 0 or warn; system('/bin/ksh', $cmd_file) == 0 or warn; unlink $cmd_file; __END__ % steph@ape (/home/stephan/t2) % % perl driver.pl $VAR1 = [ '/bin/ksh', '-c', ' cat bag\\\'cmds "more cmds" | sh ' ]; ./bin/sh -c '/bin/ksh -c ...' just another shell hacker just another perl hacker .done .directly: at the mercy of your system shell ->sh just another shell hacker just another perl hacker .done .generating script 1 $ 2 cat bag\'cmds "more cmds" | sh$ 3 $ just another shell hacker just another perl hacker .done
    cheers --stephan
Re: Unable to get a tcshell command line working in PERL v5 system command
by Crackers2 (Parson) on Jul 13, 2007 at 15:21 UTC

    I don't know how active or maintained it is, but there appear to be some modules to interface with ClearCase on this site

    I know it's not a direct answer to your question, but I may allow you to avoid having to shell out to cleartool directly.

Re: Unable to get a tcshell command line working in PERL v5 system command
by cdarke (Prior) on Jul 13, 2007 at 13:38 UTC
    How are you quoting the command inside system()? If you are doing:
    system(cleartool blah blah blah...);
    Then the problem is that the command inside () must be quoted, for example:
    system(q{cleartool blah blah blah...});