469,323 Members | 1,610 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

how to execute command and get it's result?

in perl
we can execute command and get result(command line stdout) by

$a=`cmdline parameter`;
print $a;

in c
system('cmdline parameter');
but i can not get the result (command line stdout).

in c++?
================================================== ===
have any standard method do this job?
Jun 21 '07 #1
7 15368
sonet wrote:
in perl
we can execute command and get result(command line stdout) by

$a=`cmdline parameter`;
print $a;

in c
system('cmdline parameter');
but i can not get the result (command line stdout).
Direct the output to a file and read the file.

--
Ian Collins.
Jun 21 '07 #2
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.comwrote:
sonet wrote:
in perl
we can execute command and get result(command line stdout) by
$a=`cmdline parameter`;
print $a;
in c
system('cmdline parameter');
but i can not get the result (command line stdout).

Direct the output to a file and read the file.
This of course assuming that whatever interprereter
system() invokes supports redirections.

Jun 21 '07 #3
Yes!
I can use system systemcall and direct the output to a file
and read the file. May be it is like.

system("cmdline parameter file");

But if the program is cgi,we need generate a random filename.
It may be a solution,but the method look very stupid.
Have any other smart method to read the stdout from other command line?
"Spiros Bousbouras" <sp****@gmail.com>
11**********************@w5g2000hsg.googlegroups.c om...
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.comwrote:
>sonet wrote:
in perl
we can execute command and get result(command line stdout) by
$a=`cmdline parameter`;
print $a;
in c
system('cmdline parameter');
but i can not get the result (command line stdout).

Direct the output to a file and read the file.

This of course assuming that whatever interprereter
system() invokes supports redirections.

Jun 21 '07 #4
sonet wrote:

Please don't top-post.
>
"Spiros Bousbouras" <sp****@gmail.com>
11**********************@w5g2000hsg.googlegroups.c om...
>On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.comwrote:
>>sonet wrote:
in perl
we can execute command and get result(command line stdout) by
$a=`cmdline parameter`;
print $a;
in c
system('cmdline parameter');
but i can not get the result (command line stdout).
Direct the output to a file and read the file.
This of course assuming that whatever interprereter
system() invokes supports redirections.
Yes!
I can use system systemcall and direct the output to a file
and read the file. May be it is like.

system("cmdline parameter file");

But if the program is cgi,we need generate a random filename.
It may be a solution,but the method look very stupid.
Have any other smart method to read the stdout from other command
line?
There will be a better way, but it will be platform specific, so try the
question on a group dedicated to your OS.

--
Ian Collins.
Jun 21 '07 #5
On 6 21 , 2 38 , Ian Collins <ian-n...@hotmail.comwrote:
sonet wrote:

Please don't top-post.


"Spiros Bousbouras" <spi...@gmail.com>
1182404061.265973.200...@w5g2000hsg.googlegroups.c om...
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.comwrote:
sonet wrote:
in perl
we can execute command and get result(command line stdout) by
$a=`cmdline parameter`;
print $a;
in c
system('cmdline parameter');
but i can not get the result (command line stdout).
Direct the output to a file and read the file.
This of course assuming that whatever interprereter
system() invokes supports redirections.
Yes!
I can use system systemcall and direct the output to a file
and read the file. May be it is like.
system("cmdline parameter file");
But if the program is cgi,we need generate a random filename.
It may be a solution,but the method look very stupid.
Have any other smart method to read the stdout from other command
line?

There will be a better way, but it will be platform specific, so try the
question on a group dedicated to your OS.

--
Ian Collins.- -

- -
maybe you can use 'popen'

Jun 21 '07 #6
!truth wrote:
On 6 21 , 2 38 , Ian Collins <ian-n...@hotmail.comwrote:
>sonet wrote:
>>"Spiros Bousbouras" <spi...@gmail.com>
1182404061.265973.200...@w5g2000hsg.googlegroups .com...
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.comwrote:
sonet wrote:
>in perl
>we can execute command and get result(command line stdout) by
>$a=`cmdline parameter`;
>print $a;
>in c
>system('cmdline parameter');
>but i can not get the result (command line stdout).
Direct the output to a file and read the file.
This of course assuming that whatever interprereter
system() invokes supports redirections.
Yes!
I can use system systemcall and direct the output to a file
and read the file. May be it is like.
system("cmdline parameter file");
But if the program is cgi,we need generate a random filename.
It may be a solution,but the method look very stupid.
Have any other smart method to read the stdout from other command
line?
There will be a better way, but it will be platform specific, so try the
question on a group dedicated to your OS.
*Please* don't quote signatures.
>
maybe you can use 'popen'
Not if you OS doesn't have popen(), that's why I suggested a platform
specific group.

--
Ian Collins.
Jun 21 '07 #7
"sonet" <so*******@msa.hinet.netwrote:
# in perl
# we can execute command and get result(command line stdout) by
#
# $a=`cmdline parameter`;
# print $a;
#
# in c
# system('cmdline parameter');
# but i can not get the result (command line stdout).
#
# in c++?
# ================================================== ===
# have any standard method do this job?

Since the C standard doesn't even interpret the string in the
system() call, you're out of luck with the C standard.

Other standards provide additional methods, such as the
popen in unix and some other systems. Unix also provides
additional ways to redirect stdin, stdout, and stderr
separately.

Decide what systems you're willing to abandon and code
to that standard.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Who's leading this mob?
Jun 24 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by tom | last post: by
1 post views Thread by Valentine Kouznetsov | last post: by
5 posts views Thread by =?Utf-8?B?Sm9iIExvdA==?= | last post: by
13 posts views Thread by Martin Sand Christensen | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.