In addition to what you said, there's also the problem that the
output the OP wants likely is from the bash builtin "time".
Perl, however, is typically configured to call /bin/sh as the
default shell (see perl -V:sh). And as sh doesn't know
the time builtin (even if /bin/sh is just a link to /bin/bash
— for compatibility reasons, the program name is what
matters here), the shell will search for an external executable "time",
which usually is /usr/bin/time. The latter produces a different
output format, though.
To sum up, what the OP probably wants is
my $times = `/bin/bash -c "(time ls) 2>&1 >/dev/null"`;
Compare
#!/usr/bin/perl -l
$times = `(time ls) 2>&1 >/dev/null`;
print "/usr/bin/time:\n[$times]";
$times = `/bin/bash -c "(time ls) 2>&1 >/dev/null"`;
print "bash builtin:\n[$times]";
__END__
/usr/bin/time:
[0.00user 0.00system 0:00.00elapsed 114%CPU (0avgtext+0avgdata 0maxres
+ident)k
0inputs+0outputs (0major+396minor)pagefaults 0swaps
]
bash builtin:
[
real 0m0.008s
user 0m0.004s
sys 0m0.004s
]
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|