473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I store output of linux system calls into a file or a variable?

2 New Member
I am writing a 'C' program to implement advanced shell which will allow me pipes and redirection so please tell me how can I store the out of system calls to a file or variable.
Mar 16 '11 #1
1 2890
mac11
256 Contributor
The fact that you say "the out of system calls" leads me to believe that you're using the system() function (from stdlib.h) to run commands.

Is that correct?

Assuming it is, you aren't really writing a shell, you're writing a program that runs on top of a shell. To do what a shell does you'll use fork() and exec() and pull the output from stdout/stderr directly instead of using system() to tell bash (or whatever) to run the command for you.

Using system() you have to redirect the output to a file and then read that file.

So, if you want to get the output of the ls command you do
Expand|Select|Wrap|Line Numbers
  1. system("ls > /tmp/ls.output");
and then open the ls.output file and read the content.

There are many other ways to do it, but you didn't explain much about the architecture of your program or your goals.
Mar 17 '11 #2

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

Similar topics

2
by: Birch | last post by:
I have a python script that uses the print function throughout, and as well uses calls to os.system() to spawn DOS commandline executables. My issue is that I redirect all of the output from this...
3
by: igthibau | last post by:
Hello one and all, Hopefully someone can help me out here. I am trying within a C / C++ program to invoke command line instructions (under linux) i.e.: say I wish to list the contents of the...
5
by: markus | last post by:
Hi, I have a question that deals with the standard c library VS (Unix) system calls. The question is: which header files (and functions) are part of the C library and which header files (and...
22
by: markus | last post by:
Hi, There are more than 1000 defined system calls in the Unix standard specification, however, a majority of them are optional and the availability of system calls are dependent on the OS...
3
by: Dbug | last post by:
How does C# implement system calls in the old terms? As in C system("OSfunction"); I want to copy a file to the printer port for direct PCL (printer control language) execution. In cmd it will be...
0
by: SampathTangudu | last post by:
Hi, We are trying to use the Hash Tables for passing information from one aspx page to another aspx page. We are using the below code. IsolatedStorageFile isoStore =...
11
by: talk | last post by:
hi,guy i have a question. are the functions in <stdio.h> system calls provided by operation system? if so, i want to know how C implements that we can call system calls by using the functions in...
21
by: omkar pangarkar | last post by:
Hi all, I have two simple hello world programs one using printf() and other using write() --prog 1-- #include<stdio.h> #include<stdlib.h> int main() { printf("Hello"); /* up to here...
0
by: Concepts Systems | last post by:
Hello All, Advance C and Linux System Programming are an intensive hands-on course designed by Concepts Systems to provide a detailed examination of each topic. These modules enable...
0
by: Concepts Systems | last post by:
Hello All, With a growing demand for Linux System Professionals, we are pleased to announce a new weekend batch of "Advance C" and "Linux System Programming" for working professionals and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.