By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

how to execute command and get it's result?

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
!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

P: n/a
"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.