sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Oliver Witt's Avatar

Interact with console application


Question posted by: Oliver Witt (Guest) on August 21st, 2008 02:05 PM
Hi,

I am coding a c++ application that is supposed to be capable of
altering large text files. I want to use sed to do this. So I need to
know how I can start sed from within the c++ program and how to get
the return value (I do not want to write the result immediately into a
file).

This is another question, a little off topic, but if somebody happens
to know... This program will be running on a Windows machine. I do not
know how to tell sed if it is dealing with Unicode or Ascii encoded
files.

Thanks for any help,

Oliver
2 Answers Posted
Jorgen Grahn's Avatar
Guest - n/a Posts
#2: Re: Interact with console application

On Thu, 21 Aug 2008 06:04:01 -0700 (PDT), Oliver Witt <olliwitt@googlemail.comwrote:
Quote:
Originally Posted by
Hi,
>
I am coding a c++ application that is supposed to be capable of
altering large text files. I want to use sed to do this.


So you'll use "sed -i ..."; otherwise you cannot alter the files in
place.
Quote:
Originally Posted by
So I need to
know how I can start sed from within the c++ program and how to get
the return value (I do not want to write the result immediately into a
file).


Use the ANSI C system() call. There are similar situations where
you'd rather use popen(), like if you want your C++ code to interpret
sed's output. Windows may have similar calls named Spawn-something.
Quote:
Originally Posted by
This is another question, a little off topic, but if somebody happens
to know... This program will be running on a Windows machine. I do not
know how to tell sed if it is dealing with Unicode or Ascii encoded
files.


Sorry, no. But what Unicode do you mean? There's UTF-8, and then
there are encodings with 16 bits per character and so on. I'm not
familiar with Windows.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se R'lyeh wgah'nagl fhtagn!
Oliver Witt's Avatar
Guest - n/a Posts
#3: Re: Interact with console application

Use the ANSI C system() call. *There are similar situations where
Quote:
Originally Posted by
you'd rather use popen(), like if you want your C++ code to interpret
sed's output. *Windows may have similar calls named Spawn-something.


popen() is what I have been looking for. Thank you.
Quote:
Originally Posted by
Sorry, no. But what Unicode do you mean? *There's UTF-8, and then
there are encodings with 16 bits per character and so on. *I'm not
familiar with Windows.


UTF8 works fine, UTF16 is the problem. I believe I will just convert
UTF-16 to UTF-8.

Oliver
 
Not the answer you were looking for? Post your question . . .
197,047 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,047 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors