473,805 Members | 1,980 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 15766
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
2074
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
11017
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
1956
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 in a generic way, but im out of options...
3
1335
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
8017
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
1154
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
1224
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 application level and deal with them myself. I already tried the "rowsaffected" property but that...
5
5855
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 = new ProcessStartInfo("xcopy", ""); info.FileName = "xcopy"; info.Arguments = string.Format("\"{0}\"...
13
1824
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
9596
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10607
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
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
3
3007
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.