popen() to execute\read a Linux (not windows) command

Rob Shearman rob at codeweavers.com
Tue Nov 22 18:14:48 CST 2005


Sergio Tridente wrote:

>Sergio wrote:
>
>>Hi,
>>
>>>From a win32 program compiled with winelib I am trying to execute the
>>following:
>>FILE *program;
>>if (program = popen("dcop amarok player nowPlaying", "r"))
>>        fgets(buff, sizeof(buff), program);
>>The idea is to read the current track amarok's playing. But I keep
>>receiving the following text: "File not found". Later I tried changing to
>>: popen("ls", "r"), and the same problem arised. Finally I changed to
>>popen("dir", "r") and then I got some data read (first line of the dir
>>command). So, what I understand is that the popen function is
>>opening/reading only windows programs. How can I make it open a pipe on a
>>Linux' one? Is there something like linux_popen()?
>>
>>Thanks. Sergio.
>>    
>>
>
>OK. It's me, the same person of the original post (I just changed my e-mail
>adress).
>
>I just imagined that what I needed to do could be achieved by creating a
>separate source file which will be compiled using gcc against the standard
>linux's libraries. Then I compiled the rest of the program and linked
>everything together. Now, when I tried to run the application to just do:
>program = popen("ls .", "r")
>I got a message in the console saying "err: broken pipe".
>To make the binary I did:
>1) gcc -c linuxsource.c -o linuxsource.o
>2) wingcc -c restofprogram.c -o restofprogram.o
>3) To link: wingcc -share binaryname.spec restofprogram.o linuxsource.o 
>resource.res -L/usr/local/lib/wine -lwine -lmsvcrt -lgdi32 -lshell32
>  
>

Here is the problem ^ you are linking with msvcrt so you are getting the 
msvcrt version of popen.

>-lole32 -lcomctl32 -lcomdlg32 -o binaryname.dll
>And well, I am actually making a dll not a program.
>

Rob



More information about the wine-devel mailing list