473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to reroute a system call output to local variable in C++?

13
Hello,

For example, I can do this call to get the output to a text file:

system("dir > temp.txt");

But does anyone know how to get the output to a local variable like CString or char*?

Thanks in advanced.
-weeg
May 13 '08 #1
7 2396
Laharl
849 Expert 512MB
You mean other than opening temp.txt and reading its contents using C++?
May 13 '08 #2
Weegee
13
Yep. I'd like to skip the i/o step, and process the string directly...that is if it's possible.
May 13 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Just use printf or cout on your CString and redirect yout program output to a text file.

CString means you are probably using Visual Studio.NET and that means you go to your project properties for Debugging and put in your command line arguments like >testout.txt. You don't use the program name as a command line argument.
May 13 '08 #4
oler1s
671 Expert 512MB
Look at the idea of pipes. And piping streams. A UNIX function that's a good search term for the entire topic is popen. Try those, and read about it. Windows can execute a process, and pipe output of the spawned process to your program. Look around, and you'll find out how.
May 13 '08 #5
RRick
463 Expert 256MB
The problem you have is with the system command. It will run a command for you, but the only return value from system is the return code from the command string. System redirects all output to STDOUT, and I don't know of any way to easily catch that info.

Also, I don't know any other C/C++ command you can use. Other languages (like bash and perl) have mechanisms to collect output, but C/C++ seems to be missing these mechanisms.
May 13 '08 #6
arnaudk
424 256MB
If all you want to do is get a directory listing, you might check out boost::filesystem, or have a look through windows file management on msdn.
May 13 '08 #7
Weegee
13
Thanks everyone for giving me some suggestions! :) I went ahead and searched around and found CreateProcess(). It's a little involved, but I finally got it working for what I needed to do.

Thanks again!
-weeg
May 14 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the...
1
by: Mark | last post by:
Here is a description of automatic client reroute in DB2 V8.2 "The automatic client reroute feature allows client applications to recover from a loss of communication with the server so that they...
3
by: Shi Jin | last post by:
Hi there, I am now having a puzzle regarding what a function call actually does when called. I have a simple code to see what's going on. It is simply calling another simple function from...
3
by: Pab | last post by:
I'm trying to use the client reroute feature of the DB2 Universal JDBC driver. I found documentation on this in the "Application Development Guide: Programming Client Applications" in the section...
22
by: SF | last post by:
Hello All, In a windows C learning project I am wokring on I use the system function to run a command, I want to suck the results into a vairable. The system function seems to only return an...
3
by: rrs.matrix | last post by:
hi is there any system call in unix that will search for a file in the filesystem. someting like the find utility. if not then how should i search for a file in the file system. heard of...
2
by: Eric Price | last post by:
Hi; I have a couple bugs to work out in the below script; namely, I don't know how to capture the result of an os.system command, nor am I convinced that the call to os.system actually results in...
10
by: hummingbirdlj | last post by:
I have a couple questions about setting up automatic client reroute. First, after setting the alternate server for a database, is there a way to verify the settings later on? The next thing is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.