473,394 Members | 1,724 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,394 software developers and data experts.

Using bash commands in C

78
Hi guys.
I'm working on an assignment that requires me to use the output of ls(1) as an input of wc(1). The problem is i don't know how to call ls or wc in C. I only know how to execute them using system(), i.e. directly in the shell.
Can anyone help me here? I've searched and found nothing on the web. I need to save the output of ls in a buffer or something, and somehow excute wc in and store that output too, in order to print if later.

Thanks alot!
Apr 3 '07 #1
4 2009
Sebouh
78
Well thanks for the reply guys ;)
I think i found the answer. It has to do with pipes...popen().
Now i only need to know how to use it.
cheers.
Apr 3 '07 #2
sicarie
4,677 Expert Mod 4TB
Sebouh-

Good job finding that, and thanks for posting again when you found it! Best of luck, sorry we couldn't help this time, but feel free to post again.
Apr 3 '07 #3
horace1
1,510 Expert 1GB
Hi guys.
I'm working on an assignment that requires me to use the output of ls(1) as an input of wc(1). The problem is i don't know how to call ls or wc in C. I only know how to execute them using system(), i.e. directly in the shell.
Can anyone help me here? I've searched and found nothing on the web. I need to save the output of ls in a buffer or something, and somehow excute wc in and store that output too, in order to print if later.

Thanks alot!
not sure what you are trying to do
you could use system directly to pipe the output of ls to wc
Expand|Select|Wrap|Line Numbers
  1.     system("ls -l | wc"); 
  2.  
or redirect the streams, e.g. output the result of ls to file x
Expand|Select|Wrap|Line Numbers
  1.     system("ls -l > x"); 
and input it to wc
Expand|Select|Wrap|Line Numbers
  1.     system("wc < x"); 
Apr 3 '07 #4
Sebouh
78
Yes that's possible, but each of ls and wc has to run by a different process and transfer data, so...
Apr 4 '07 #5

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

Similar topics

4
by: DvDmanDT | last post by:
Hello, I have an intresting problem: I want to let users upload sourcecode and then compile it using my cygwin gcc... But one thing at a time... I can't get that gcc to execute... ...
3
by: Bernhard Kuemel | last post by:
Hi! To relief the problems of accessing a unix machine from behind a restrictive firewall or from an internet cafe I started to make a PHP web interface to bash. I'd like to hear your opinions...
2
by: Tobias Hesselmann | last post by:
Hi folks, i have a problem using a PHP script as a custom handler in Apache. What i wanna do is this: Whenever a .html file is requested by a browser, i want Apache to call a CGI that outputs...
4
by: bill | last post by:
Consider the following: import os, commands os.environ="string with foo" a = '$QWE ${QWE/foo/baz}' b = commands.getoutput('echo ' + a) This does what I want, which is to expand a...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
by: Tim Golden | last post by:
Tim Golden enlightened us with: > > Well, I'm with you. I'm sure a lot of people will chime in to point > > out just how flexible and useful and productive Linux is as a > > workstation, but every...
4
by: 4zumanga | last post by:
I have a bunch of really horrible hacked-up bash scripts which I would really like to convert to python, so I can extend and neaten them. However, I'm having some trouble mapping some constructs...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
4
by: melmack3 | last post by:
Hello My PHP script executes many bash/cmd commands. Functions like "exec()" or "system()" cause that new bash/cmd session is started, the command is executed and the session is closed....
6
by: Frantisek Malina | last post by:
What is the best way to do the regular bash commands in native python? - create directory - create file - make a symlink - copy a file to another directory - move a file - set permissions ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
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
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...
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...

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.