473,585 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15754
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.co mwrote:
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.c om>
11************* *********@w5g20 00...legro ups.com...
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
>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.c om>
11************* *********@w5g20 00...legro ups.com...
>On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
>>sonet wrote:
in perl
we can execute command and get result(command line stdout) by
$a=`cmdlin e parameter`;
print $a;
in c
system('cmdl ine 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.co mwrote:
sonet wrote:

Please don't top-post.


"Spiros Bousbouras" <spi...@gmail.c om>
1182404061.2659 73.200...@w5g20 00hsg.googlegro ups.com...
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
sonet wrote:
in perl
we can execute command and get result(command line stdout) by
$a=`cmdline parameter`;
print $a;
in c
system('cmdli ne 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.co mwrote:
>sonet wrote:
>>"Spiros Bousbouras" <spi...@gmail.c om>
1182404061.26 5973.200...@w5g 2000hsg.googleg roups.com...
On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
sonet wrote:
>in perl
>we can execute command and get result(command line stdout) by
>$a=`cmdlin e parameter`;
>print $a;
>in c
>system('cm dline 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("cmdli ne 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2061
by: tom | last post by:
Problem: In PHP, need to execute a program in (freebsd terms) /usr/local/bin in meta-terms: int i; i = (arguments); There seems to be quite a few execution methods in PHP (sorry in advance for being thick), and, er, I was wondering if someone could give me a quick pointer to appropriate ones I should study to:
1
11001
by: Valentine Kouznetsov | last post by:
Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If I do os.system() then sub-shell will setup A and execute my script there leaving A in parent shell untouched. Thanks,
1
1945
by: Ben Floyd | last post by:
It goes like this: Im converting a perl script that executes a command on each result of a directory listing. In perl, all is well. In Python, using approximately the same logic creates a seemingly random problem I can't pin down. I hesitated to ask this question since it's so Slackware Linux-centric, and im new to Python. It's hard to ask...
3
1326
by: Hagge | last post by:
Hi, I'm working on a application where I've created a couple of Sub routines I call them from my ASP page. But I would love to put the hole HTML including my "call showOffers" in my database and when I get the result set do I want to execute the "call showOffer". Is this possible? If it's how is it possible? // Hagge
3
8004
by: Me | last post by:
hi, I have this file I need to execute from an ASP client. since we have installed it on the SQL Database server machine, I thought I could run it like this: Set Cn = CreateObject("ADODB.Connection") Cn.CursorLocation = adUseClient Cn.ConnectionTimeout = 0
0
1146
by: kk.simhadri | last post by:
Hi all I want to run a bat file in the server through an ASP page. The following is the code in my ASP page. <html> <body> <html> <body> <form runat="server">
0
1216
by: David Greenberg | last post by:
Hello I'm calling a stored procedure in VB6 using the "execute" command of rdoquery. Does anyone know how to check whether or not the execute command was succesfull or not. Not on the level of whether any rows were updated or selected but whether any Sql errors occured. VB picks up on any errors but I want to be able to identify them on the...
5
5846
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
I am having issues copying files from network drive to local machine using xcopy. The following code works alright for a console application, but as soon as i call this code in Form Load event of windows application it does not work. I am confused here, it copies files in a console application, but not windows app ProcessStartInfo info =...
13
1803
by: Martin Sand Christensen | last post by:
Hi! First a bit of context. Yesterday I spent a lot of time debugging the following method in a rather slim database abstraction layer we've developed: ,---- | def selectColumn(self, table, column, where={}, order_by=, group_by=): | """Performs a SQL select query returning a single column
0
7900
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8192
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5382
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3828
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1167
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.