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

Re: Using "wc" inside C program

yes it is supposedly easier to use a temporary file, but is it possible
to use popen() for the given instance ?
how can the required read and write achieved using popen(), when as you
mentioned popen() allows only one at a time ?

-- Satish
On Sun, 2008-11-16 at 18:56 +0000, Richard Tobin wrote:
In article <52**********************************@1g2000prd.go oglegroups.com>,
Snaggy <l.******@gmail.comwrote:
Or any other standar unix program..
I want to pass something to a pipe for wc (to count words) and read
the result into a variable..

For now I put an intermediate result into a file and then open the
file and read it..

Reading and writing to another program through pipes is, in general, a
recipe for deadlock. In the case of "wc" this wouldn't be a problem,
but if you were using something like "tr" it would. To make it work
requires some kind of asynchronous (or select()ed) i/o, multiple
threads, or arbitrary buffering in the operating system. Consequently
the unix popen() call only provides for you to either read or write,
not both.

For this simple case, your solution of using a temporary file is
probably the easiest, requiring little unix-specific knowledge.

-- Richard
Nov 16 '08 #1
4 2124
eerpini wrote:
>
yes it is supposedly easier to use a temporary file, but is it
possible to use popen() for the given instance ? how can the
required read and write achieved using popen(), when as you
mentioned popen() allows only one at a time ?
Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)
<http://members.fortunecity.com/nnqweb/ (newusers)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 16 '08 #2
In article <12**********************@localhost.localdomain> ,
eerpini <ee*****@gmail.comwrote:
>yes it is supposedly easier to use a temporary file, but is it possible
to use popen() for the given instance ?
You can use popen() to send it the input through a pipe, with the
result going to a file you read later. Or you can put the input in a
file, and use popen() to read the result. You can't use popen() to
get a pipe for both input and output.

To use a pipe for both input and output, you have to do something much
more complicated, such as using pipe(), fork(), and exec() to set up
the process, and select() to handle the reading and writing. It's
not worth the trouble in most cases.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 16 '08 #3
Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:
sorry for that , went through the links,
Thanks

Nov 16 '08 #4
eerpini wrote:
>
>Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

sorry for that , went through the links,
Good for you. That's why I try to respond to top-posters early.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 16 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
19
by: Alex Vinokur | last post by:
Is there any tool to count C-program lines except comments? Thanks, ===================================== Alex Vinokur mailto:alexvn@connect.to http://mathforum.org/library/view/10978.html...
2
by: ramasubramanian.rahul | last post by:
i am trying to implement the unix command ls -l | wc -l in c...( using pipes and excev) its not working.... can anyone help me here ??? thanks in advance rahul #include<stdio.h> 2 #include...
9
by: Notre Poubelle | last post by:
Hello, I've created a regular (as opposed to extension) DLL that has MFC support (in a shared DLL). Everything works fine. I then decided to modify my configuration so that on the project...
8
by: Rui Maciel | last post by:
I've just started learning how to use the wchar_t data type as the basis for Unicode strings and unfortunately I'm having quite a bit of problems, both in the C front and the Unicode front. In...
3
by: dwblas | last post by:
The annual Linux Journal survey is online now for any Linux users who want to vote for Python. http://www.linuxjournal.com/node/1006101
3
by: Ioannis Vranos | last post by:
Is printf("%ls") for printing wchar_t strings defined in C90, or it was added in C95?
16
by: hiteshthappa | last post by:
hi Can anyone please help me in finding the total number of words in a file I get the newlines, characters and blankspaces correctly but counting words ia problem.I have tried many ways but it...
5
by: Snaggy | last post by:
Or any other standar unix program.. I want to pass something to a pipe for wc (to count words) and read the result into a variable.. For now I put an intermediate result into a file and then...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...

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.