LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2005, 04:20 PM   #1
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
popen for windows


Hi,

I need to issue a system command and parse the output in my program. This program will actually be runtime libraries for Windows, UNIX and Linux. On UNIX/Linux I used popen to run the command and get the output, for windows I used _popen. However _popen works as a windows console application, but fails to read the output of the command in a dll.

Does anyone know another way to issue commands and get output back in widnows? Thanks.
 
Old 11-17-2005, 09:43 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
The _popen() is what should be used on windows, there isn't much else you can do.
On windows this function takes the command string and gives it to the cmd.exe program to execute so the syntax of your command string must be correct for this shell language, i.e. a unix style 'sh' script will not work here.

You could also look at ShellExecute() which is a slightly lower level function that bypasses cmd.exe and does similar funciton on windows.
 
Old 11-18-2005, 01:49 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
It's a pain in the butt, but several years ago I had success with this MSDN article:

"How to spawn console processes with redirected standard handles":
http://support.microsoft.com/default...b;en-us;190351
 
Old 11-19-2005, 01:39 PM   #4
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Man that MSDN article is brutal! Tried it several years ago too
and I couldn't get it to work very well.
I just thought of another idea, in Windows the CreateNamedPipe()
method works great. Its about the only way I know of
besides sockets that works really well in windows for streaming
data between processes.
Since windows stdio is so poorly implemented, I've always
resorted to creating cross-platform libraries that implemented
it different ways depending on where it was compiled.
On windows I used the named pipes, and on Unix used the
stdio interfaces to do the same work. Painful, for sure.
 
Old 11-29-2005, 03:06 PM   #5
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Original Poster
Rep: Reputation: 31
Thanks for the replies guys, I found the solution to my problem.

luckly my dll will only run as console application, as soon as I changed the project setting to use "multithreaded dll" during linking (/MD option in the Project Options) _popen works.

Thanks again.
 
Old 11-29-2005, 11:24 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You aren't calling _popen in DllMain(), are you? That would be Bad...
 
Old 11-30-2005, 08:21 AM   #7
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Original Poster
Rep: Reputation: 31
no, I am not
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
popen output not appear dimsh Programming 4 10-22-2005 02:56 AM
where do i get a bidirectional popen pipe? Thinking Programming 9 10-21-2005 07:42 AM
Help needed with system() and popen! twirl Programming 4 09-14-2005 09:22 AM
Multithreading and os.popen in wxPython wapcaplet Programming 0 12-29-2004 07:58 PM
C Popen gold5angel Programming 2 04-17-2004 07:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration