Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Capturing bash output without displaying STOUT in terminal

by stevieb (Canon)
on Sep 08, 2016 at 16:08 UTC ( #1171409=note: print w/replies, xml ) Need Help??

in reply to Capturing bash output without displaying STOUT in terminal

You can use the qx operator or backticks to do pretty much the same thing as system, but it'll capture the STDOUT (it doesn't capture STDERR though).

use warnings; use strict; my $stdout = qx{ git status }; # or `git status` ...

See Quote and Quote-Like Operators in perlop.

Replies are listed 'Best First'.
Re^2: Capturing bash output without displaying STOUT in terminal
by edimusrex (Monk) on Sep 08, 2016 at 16:14 UTC
    The issue is using the backticks or qx, the stdout is still diplayed in the console and nothing is captured in the variable. Maybe it's the specific command I am running.

      What is the output on screen you get?

      Try running something you know won't error out and write to STDERR instead of STDOUT. For instance:

      my $out = `ls`;

      ...should NOT write to STDERR. If that works, but your original command doesn't, I'm pretty certain that something is happening that is writing to STDERR.

      Try doing a git status with backticks and see what happens. Now move the test to a non-repo directory and compare the results (the latter will print to console, the former won't).

        I tried this, and it doesn't work for 'git fetch --tags' for some reason.

        My guess is that using this command produces some sort of 'active' output (for want of a better description) in the terminal, and it isn't a static output like you would get from backticks 'ls' or 'ps ax' etc.

        Now for some reason, once you run 'git fetch --tags', any other time you run it, there is no output - I don't know how to reset it to test - but maybe try saving the command in a text file chmod 755 and then use

        my $git = `.\`;

        BTW, using 'my $git = `git status`; works:

        :~/git/claws/claws$ perl gittest What's here? --- On branch master Your branch is up-to-date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) gittest nothing added to commit but untracked files present (use "git add" to +track)


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2023-06-01 16:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found