🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5750

problem with processes and pipes

#5750
From: Serkan �zkan
Date: Sun, 10 Jul 2005 06:41
43 lines
2836 bytes
Hi,
I am working on a client-server project, and have a problem on the client 
side.
I execute commands on the client side with cmd.exe and send the output to 
server.
More clearly I first
-create pipes to redirect stdout and stdin of child process

-call CreateProcess to create the process, with pipes as stdin and out. (the 
process created is something like "c:\windows\system32\cmd.exe /C 
thecommand". path of cmd.exe is acquired from ComSpec environment variable.)

-start a thread to read the output of the child process.
   --This thread calls ReadFile and appends the data read to a 
std::vector<TCHAR*>. To syncronize access to the vector I used a mutex, no 
thread manipulates the vector without acquiring mutex.
   --I also handled (I guess but not sure) pending io case 
(ERROR_IO_PENDING) for ReadFile.

-main thread sends the data in the vector to the server using socket 
connection

My problem is; if I execute "dir" as command everything works fine. But for 
example if I execute a net command like "new view" I get access violation 
errors or I get various code guard  messages like reference to freed memory, 
invalid memory location etc while trying to send the data to the server.

I guess I am not handling reading of data from the pipe properly. In fact I 
didn't understand overlapped structure clearly, should I use it and if so 
how should I use it? Or should I use ReadFileEx, which also uses overlapped 
structure.

And one other question not directly related to the other question, how 
should I send unicode data using sockets? send accepts char* but not 
wchar_t*. Should I convert it using WideCharToMultiByte or what should I do? 
What is the best way of doing this?


Thanks in advance

(By the way I know I should send a simplified version of the code but I 
could not create a simplified piece of code that creates the same errors, 
because that would not be a simple and short piece of code.) 
Technical Details
Message-ID: <42d0c32b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,94749c832783b174,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Serkan �zkan" <serkan@insaat.org>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: problem with processes and pipes 
Date: Sun, 10 Jul 2005 09:41:56 +0300
Lines: 45
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 85.97.63.204
Message-ID: <42d0c32b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1120977707 85.97.63.204 (9 Jul 2005 23:41:47 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail