Last active
December 26, 2015 17:59
-
-
Save libitte/7190478 to your computer and use it in GitHub Desktop.
Perl * system() ... 2>&1 で、出力させつつ、戻り値としては $? を返す。
* `` ... 2>&1 で出力させた結果を戻り値とする。なお、改行コードも含まれる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
print "- system\n"; | |
print "-----------------\n"; | |
my $ret_sys = system 'ps aux | grep -v grep | grep perl | wc -l'; | |
print '$ret_sys is ', $ret_sys; | |
print "\n"; | |
print "-----------------\n"; | |
print "\n"; | |
=pod | |
system | |
標準出力を出力しつつ、 | |
戻り値として $? を返す。 | |
=cut | |
print "- backquote\n"; | |
print "-----------------\n"; | |
my $ret_bq = `ps aux | grep -v grep | grep perl | wc -l`; | |
print chomp($ret_bq); # $ret_bq は改行コードも含む | |
print "\n"; | |
print "-----------------\n"; | |
=pod | |
`` | |
標準出力, 標準エラー出力を返す | |
`command` 2>&1 | |
=cut | |
__END__ | |
- system | |
----------------- | |
2 | |
$ret_sys is 0 | |
----------------- | |
- backquote | |
----------------- | |
1 | |
----------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
print "- system\n"; | |
print "-----------------\n"; | |
my $ret_sys = system 'ls $HOME/.nvm'; | |
print '$ret_sys is ', $ret_sys; | |
print "\n"; | |
print "-----------------\n"; | |
print "\n"; | |
=pod | |
system | |
標準出力を出力しつつ、 | |
戻り値として $? を返す。 | |
=cut | |
print "- backquote\n"; | |
print "-----------------\n"; | |
my $ret_bq = `ls \$HOME/.nvm`; | |
print $ret_bq; # $ret_bq は改行コードも含む | |
print "-----------------\n"; | |
=pod | |
`` | |
標準出力, 標準エラー出力を返す | |
`command` 2>&1 | |
=cut | |
__END__ | |
- system | |
----------------- | |
README.markdown | |
alias | |
bash_completion | |
bin | |
install.sh | |
nvm.sh | |
test | |
v0.10.0 | |
$ret_sys is 0 | |
----------------- | |
- backquote | |
----------------- | |
README.markdown | |
alias | |
bash_completion | |
bin | |
install.sh | |
nvm.sh | |
test | |
v0.10.0 | |
----------------- |
Author
libitte
commented
Oct 28, 2013
- system() ... 2>&1 で、出力させつつ、戻り値としては $? を返す。
- `` ... 2>&1 で出力させた結果を戻り値とする。なお、改行コードも含まれる。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment