Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: ClearCase Command text in Backticks is ignored

by kennethk (Monsignor)
on May 08, 2013 at 15:30 UTC ( #1032622=note: print w/ replies, xml ) Need Help??


in reply to ClearCase Command text in Backticks is ignored

I'm not familiar with this particular tool, so this advice is generic.

If you are having trouble with escaping on a command line call that you do not need to capture output from, the easiest solution is usually multi-argument system. That way, Perl will handle escaping and quoting for you as necessary. Your call might look like:

my $output = system('cleartool', 'lsco', '-r', '-brt', $stream, '-fmt' +, '%En\t%u\n');

It's also possible that the last term there should be something more like "%En\t%u\n", which gets to why I suspect your backtick call is failing; I would guess that the format string passed can't contain literal control characters. Perhaps you'll get your desired result from:

my $output = `cleartool lsco -r -brt $stream -fmt "%En\\t%u\\n"`;
or possibly
my $output = `cleartool lsco -r -brt $stream -fmt '%En\\t%u\\n'`;

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: ClearCase Command text in Backticks is ignored
Select or Download Code
Re^2: ClearCase Command text in Backticks is ignored
by Deep_Plaid (Acolyte) on May 08, 2013 at 16:16 UTC

    Hi Ken,

    Thanks so much for your fast reply. Escaping the back slashes in the format option worked! The output using system does the format properly now. Code:
    $output = system("cleartool lsco -r -brt p_JOESDRUGS_DT_Int -fmt \"%En +\\t%u\\n\"");

    The zero is still at the end, but I can always chop that off. Output:

    .\EDC_Export\Test_file2.txt mkjohnson .\EDC_Export\Test_file3.txt mkjohnson 0

    However, I still haven't solved the first issue. I tried your advice, and this solves the problem of recognizing the content of $stream, but the command fails. I also tried it with including the double quotes escaped:

    $output = system('cleartool', 'lsco', '-r', '-brt', $stream, '-fmt', ' +\"%En\\t%u\\n\"');

    But that still fails. However, a different failure, so I'm getting closer. It's a cleartool error and it reveals it can read $stream. Output:

    cleartool: Warning: Type not found: "p_JOESDRUGS_DT_Int". 0

    So I am getting closer. I will try playing around with this combination, but any further advice would be greatly appreciated. Thanks again.

      The zero is still at the end, but I can always chop that off
      If your code is essentially
      my $output = system(...); print $output;
      then you should note that system returns the status code returned by the call, not the output of the call. There's no reason to do the print, and probably no reason to capture the return.
      I also tried it with including the double quotes escaped
      The question I should have included up front is "What is the exact syntax that works on the command line?" If you pass system '\"%En\\t%u\\n\"', I believe it should be equivalent to entering '\\"%En\\t%u\\n\\"' on the CLI, which I think is unlikely to be what you intend.

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-11-24 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (137 votes), past polls