Solved

_wpopen

Posted on 2003-12-08
5
578 Views
Last Modified: 2010-05-19
I am working with C++ and dll (d link lib). Its NOT EXE but DLL.
I have to read french characters that are generated when I execute a command line.
I was trying to use _wpopen but in vain.
Could you pls tell me:

1. What command in C++ would let me execute command line utilities so I can read them.
2. I am working with different languages so I am looking for something that is unicode based.

Thanks.
0
Comment
Question by:pb_india
  • 2
5 Comments
 
LVL 17

Expert Comment

by:rstaveley
ID: 9903449
The only reason to use _wpopen is if your command is a wide character string. The returned FILE * is the same for _wpopen as it is for _popen, containing the standard output from your command.

Like a lot of experts at EE, I'm relatively weak at i18n, because I work in a locale in which 8-bit *external* representations are used. The idea of having > 8 bit standard output is weird to me... but presumably that's what you get in locals which require > 8 bit external representation for the required character set? wchar_t streams are externally represented as char streams in my locale. I don't get to see 16-bit characters on standard output from console programs, because characters are narrowed to 8 bits. If I were to write a program which outputs raw 16-bit UNICODE, I would need to open a file in binary mode. Presumably, I'd need to make the first bytes correspond to a BOM (= byte order marker). I'd certainly need to pass a binary flag to _open to get a byte stream from the command, if the UNICODE was being written to standard output, and then read wchar_ts from the byte stream.

Sorry I can't be more helpful.... but I am interested in whatever solution you find.
0
 
LVL 2

Accepted Solution

by:
antoinebf earned 63 total points
ID: 9916005
FYI, french does not require unicode support to be read/writen... ASCII is more than sufficient.

BTW, unicode is an encoding system used to represent almost any character. The encoding can span many bytes (multi byte representation). On the other hand, wide string (wopen, wstring, etc.) always use 2 bytes to represent chars (double byte representation).

All that to say that unicode and wide strings are not the same, and not fully compatible out of the box.

Have a look at:
http://www.unicode.org/

As for your questions:
1 - The win32 api call "int system(char*)" allows you to execute command line statements from within a C++ program.
2 - If windows is an option, their MFC's CString supports Unicode and might be of some help.

hth
A.
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 62 total points
ID: 9916567
I hadn't spotted the fact that pb_india was reading French characters. The name pb_india got me into Asian-think :-)

When I type chcp at a CMD prompt here in the UK, I see my codepage is 437 (which is described here: http://www.kostis.net/charsets/cp437.htm). I believe this is the same codepage as France and the US, from the DOS table at http://www.thur.de/~igs/USEFULL/OPENDOS/usrgeng/17ugch17.htm#390. If pb_india has the same codepage for his console applications, I'd agree with antoinebf and not expect the French characters captured by _popen to require translation.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now