|
I think it's not what is looking for. He start a console program (like ipconfig.exe) and would like to retrieve the text outputted in the console (so it has nothing to do with returning data).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Cedric Moonen wrote: He start a console program (like ipconfig.exe) and would like to retrieve the text outputted in the console
Jep! This is exactly what i want...
|
|
|
|
|
nmx_de wrote: He start a console program (like ipconfig.exe) and would like to retrieve the text outputted in the console
Try myexe.exe > filename.txt in the ShellExecute which gives the output generated by the myexe.exe into filename.txt .
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
nmx_de wrote: Can anybody give me a hint please?
Hint 1
Hint 2
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
In the first line i want to thank you all for your help.
I managed to get it done like this, but i have some problems using it in another application.
When i put this code to my class and try to run a command from another function, the whole application freezes. Ok, i know that the code looks horrible, but it works a a single application.
Anybody out there with some tipps & tricks regarding this problem?
How could it be done as a class member without freezing the whole app?
Thanks, n.
<br />
#include "stdafx.h"<br />
#include <windows.h><br />
<br />
char* cmd(char *cmd);<br />
<br />
int main()<br />
{<br />
char* output = cmd("ipconfig.exe");<br />
MessageBox(0,output,"Test",0);<br />
return 0;<br />
}<br />
<br />
char* cmd(char *cmd)<br />
{<br />
HANDLE readHandle;<br />
HANDLE writeHandle;<br />
HANDLE stdHandle;<br />
DWORD bytesRead;<br />
char maxbuffer[1024];<br />
<br />
static char output[50000];<br />
SECURITY_ATTRIBUTES sa;<br />
PROCESS_INFORMATION pi;<br />
STARTUPINFO si;<br />
<br />
ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));<br />
ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));<br />
ZeroMemory(&si,sizeof(STARTUPINFO));<br />
<br />
ZeroMemory(maxbuffer, 1024);<br />
<br />
sa.bInheritHandle = true;<br />
sa.lpSecurityDescriptor = NULL;<br />
sa.nLength = sizeof(SECURITY_ATTRIBUTES);<br />
si.cb = sizeof(STARTUPINFO);<br />
si.dwFlags = STARTF_USESHOWWINDOW;<br />
si.wShowWindow=SW_HIDE;<br />
<br />
if (!CreatePipe(&readHandle,&writeHandle,&sa,NULL))<br />
return "Error";<br />
<br />
stdHandle=GetStdHandle(STD_OUTPUT_HANDLE);<br />
<br />
if (!SetStdHandle(STD_OUTPUT_HANDLE,writeHandle))<br />
return "Error";<br />
if (!CreateProcess(NULL,cmd,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))<br />
return "Error";<br />
if (!ReadFile(readHandle,output,1023,&bytesRead,NULL))<br />
return "Error";<br />
<br />
output[bytesRead]='\0';<br />
<br />
if (!SetStdHandle(STD_OUTPUT_HANDLE,stdHandle))<br />
return "Error: SetStdHandle(stdHandle) failed";<br />
if (!CloseHandle(readHandle))<br />
return "Error: CloseHandle(stdHandle) failed";<br />
if (!CloseHandle(writeHandle))<br />
return "Error: CloseHandle(stdHandle) failed";<br />
<br />
return output;<br />
}<br />
|
|
|
|
|
I am trying to write on a label.
In the OnEraseBackground function I have
pDC->TextOut(50,42,"aaaa",30);
At this location I get a black rectangle.
What do I need to do to see the text?
thanks,
sb
|
|
|
|
|
I do not know what foreground color, background color, drawing mode you are using, or if you are drawing at the right time because the code sample is missing detail.
But the last parameter you have specified in your example is incorrect - it is supposed to be the character count of the specified string (note that the documentation may be incorrect when it says "byte count"). As such, you should be specifying 4 .
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
wrote:
I am trying to write on a label.
Why you are trying TextOut on label ??
Simply use SetWindowText for that label if using MFC.
For win32 use SendMessage(handle,WM_SETTEXT,...);
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
As you are working with CDC you can simply set the text color using
SetTextColor() API which takes COLORREF as parameter.
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Any particular reason why you are writing in the OnEraseBackground() method? Why not do it in the OnPaint() method?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thats what I saw in a sample program, so I used OnEraseBackground.
I did get TextOut to work , thanks everybody.
I'm drawing on the label because I drew a histogram on it and want to put values for the tick marks on the axes. Maybe there is a smarter control to use instead ofa label?
thanks
sb
|
|
|
|
|
you can use WM_PAINT instead WM_ERASEBKGND
<br />
void CAnswer::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
<br />
dc.SetBkMode(0);<br />
dc.TextOut(50,42,"aaaa",30);<br />
}<br />
whitesky
|
|
|
|
|
Hi,
I tried several things to launch an external program :
<br />
CString command("\"D:\\USER\\PSPad editor\\PSPad.exe\" \"log.txt\"");<br />
system(command);<br />
The above code launches a command prompt that closes instantly and doesn't launch PSPad.
<br />
CString command("cmd /C \"D:\\USER\\PSPad editor\\PSPad.exe\" \"log.txt\"");<br />
system(command);<br />
The above code launches a command prompt that launches PSPad but the calling dialog looses focus until I close PSPad.
Actually I'd like to launch my program just like double clicking on "log.txt" would do (without a command prompt would be great). Is it possible ?
Thanks !
|
|
|
|
|
Tnarol wrote: I'd like to launch my program just like double clicking on "log.txt" would do (without a command prompt would be great). Is it possible ?
Use ShellExecute(...) or CreateProcess(...) API's for launching external application's
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Tnarol wrote: Is it possible ?
yes
use ShellExecute
nave
|
|
|
|
|
|
|
COOL ! It works great !
Thanks everyone.
|
|
|
|
|
And you suggested this the other day!!!
Your previous post[^]
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
|
_AnShUmAn_ wrote: And you suggested this the other day!!!
COOL !!!
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
i have a big class that uses com methods. i would like to avoid a lot of "ifs" in it, so i wanted to replace standard hresult checking with try-catch block. there are some articles on code project about that, but the problem is that i have to use VS6 for it. That causes the restriction - i don't have CAtlException.
I also noticed that constructing function that throws something (void function(something) throw(type){...} ) is not doable, because such construction is ignored by the compiler - i get a warning with such a message...
Concluding, my question is - how can i write a class that can replace hresult with exception stuff in VS6 :].
thanks for your ideas in advance
-- modified at 9:18 Wednesday 14th June, 2006
|
|
|
|
|
Perhaps macros are suitable for you, something like this:
#define CHECK(expr) { if((expr) != S_OK) throw MyException; };
where MyException is your own class. (In case of STL, you can derive it from std::runtime_error ).
A sample usage:
try
{
CHECK(CoCreateInstance(...));
. . .
}
catch( const MyException & ex)
{
}
Now you do not have if s. Anyway, within exception handler you have to provide a method for releasing objects created successfully earlier.
|
|
|
|