 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
lackner Guest
|
Posted: Thu Mar 08, 2007 9:10 am Post subject: How to run aonther application in current running applicatio |
|
|
Dear all:
I have an BCB application, which should invoke another application to
execute some command.
for example, i would like invoke a command like this: " bslw200.exe -b
19200 -e cpu1568 sbu410.hex";
How can i do it??
Thank you in advance. |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 08, 2007 9:10 am Post subject: Re: How to run aonther application in current running applic |
|
|
"lackner" <xubo (AT) bbn (DOT) cn> wrote in message
news:45ef8145$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I have an BCB application, which should invoke another application
to
execute some command.
|
Look at the CreateProcess() function in the Win32 API.
Gambit |
|
| Back to top |
|
 |
lackner Guest
|
Posted: Fri Mar 09, 2007 9:09 am Post subject: Re: How to run aonther application in current running applic |
|
|
Thank you for your hint!
but i still has problem.since my addtional application is a command line
application(bslw200.exe), it needs dos shell to run it.
here is source code:
AnsiString strCmd = AnsiString("c:\\windows\\system32\\cmd.exe /c start ");
AnsiString strCmdLine = AnsiString("f:\\bslw200.exe -b 38400 -r
sbu410.hex");
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
// Set up members of STARTUPINFO structure.
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.lpReserved = NULL;
siStartInfo.lpReserved2 = NULL;
siStartInfo.cbReserved2 = 0;
siStartInfo.lpDesktop = NULL;
siStartInfo.dwFlags = 0;
// Create the child process.
CreateProcess(
strCmd.c_str(),
strCmdLine.c_str(),
NULL, // process security attributes
NULL, // primary thread security attributes
0, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
I don't know what wrong with it. Can you help me?
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> 写入消息新闻
:45efb547$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"lackner" <xubo (AT) bbn (DOT) cn> wrote in message
news:45ef8145$1 (AT) newsgroups (DOT) borland.com...
I have an BCB application, which should invoke another application
to
execute some command.
Look at the CreateProcess() function in the Win32 API.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Mar 09, 2007 9:11 am Post subject: Re: How to run aonther application in current running applic |
|
|
"lackner" <xubo (AT) bbn (DOT) cn> wrote in message
news:45f0cfd6 (AT) newsgroups (DOT) borland.com...
| Quote: | since my addtional application is a command line
application(bslw200.exe) |
So? Every win32 application has a command line available. You can
run an application without caring whether it requires a console or
not.
| Quote: | it needs dos shell to run it.
|
A DOS console will be created automatically when CreateProcess() tries
to run a console application. The console will be freed after the
console application exits. So what exactly are you having a problem
with?
| Quote: | AnsiString strCmd = AnsiString("c:\\windows\\system32\\cmd.exe /c
start "); |
You don't need that. The OS already know which command processor to
use. You can run bslw200.exe directly instead, ie:
STARTUPINFO siStartInfo = {sizeof(STARTUPINFO), 0};
PROCESS_INFORMATION piProcInfo = {0};
CreateProcess(
NULL,
"f:\\bslw200.exe -b 38400 -r sbu410.hex",
NULL,
NULL,
0,
0,
NULL,
NULL,
&siStartInfo,
&piProcInfo);
| Quote: | I don't know what wrong with it.
|
You did not say why you think anything is wrong.
Gambit |
|
| Back to top |
|
 |
lackner Guest
|
Posted: Fri Mar 09, 2007 9:11 am Post subject: Re: How to run aonther application in current running applic |
|
|
dear Lebeau:
I have solved the problem!, thank you!
"lackner" <xubo (AT) bbn (DOT) cn> 写入消息新闻:45f0e151 (AT) newsgroups (DOT) borland.com...
| Quote: | hello Lebeau:
Actually, it doesn't work with CreateProcess(
NULL,
"f:\\bslw200.exe -b 38400 -r sbu410.hex",
NULL,
NULL,
0,
0,
NULL,
NULL,
&siStartInfo,
&piProcInfo);
there is no console open, The bslw200 command can't be execute. when
bslw200 is executing, it will look into Serial interface and wait for a
response from other component in our system, the timeout period of waiting
is quite long.
I don't know whether it is feasible to send you relative files to
you(bslw200 and so on), maybe you can see my problem more clearly.
Thanks you very much for your answer.
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> 写入消息新闻
:45f0d50e$1 (AT) newsgroups (DOT) borland.com...
"lackner" <xubo (AT) bbn (DOT) cn> wrote in message
news:45f0cfd6 (AT) newsgroups (DOT) borland.com...
since my addtional application is a command line
application(bslw200.exe)
So? Every win32 application has a command line available. You can
run an application without caring whether it requires a console or
not.
it needs dos shell to run it.
A DOS console will be created automatically when CreateProcess() tries
to run a console application. The console will be freed after the
console application exits. So what exactly are you having a problem
with?
AnsiString strCmd = AnsiString("c:\\windows\\system32\\cmd.exe /c
start ");
You don't need that. The OS already know which command processor to
use. You can run bslw200.exe directly instead, ie:
STARTUPINFO siStartInfo = {sizeof(STARTUPINFO), 0};
PROCESS_INFORMATION piProcInfo = {0};
CreateProcess(
NULL,
"f:\\bslw200.exe -b 38400 -r sbu410.hex",
NULL,
NULL,
0,
0,
NULL,
NULL,
&siStartInfo,
&piProcInfo);
I don't know what wrong with it.
You did not say why you think anything is wrong.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Mar 09, 2007 9:11 am Post subject: Re: How to run aonther application in current running applic |
|
|
"lackner" <xubo (AT) bbn (DOT) cn> wrote in message
news:45f0e151 (AT) newsgroups (DOT) borland.com...
| Quote: | Actually, it doesn't work with CreateProcess
|
Yes, it does. CreateProcess() works with DOS console applications
just fine. I have several projects of my own that run console
utilities and they run without any problems.
| Quote: | there is no console open
|
Yes, there is. It may be hidden by default, though. You can use the
STARTUPINFO structure to tell CreateProcess() to show the console
window, ie:
siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
siStartInfo.wShowWindow = SW_SHOW;
| Quote: | The bslw200 command can't be execute.
|
Yes, it can.
| Quote: | when bslw200 is executing, it will look into Serial interface and
wait for a response from other component in our system, the
timeout period of waiting is quite long.
|
CreateProcess() does not wait for the spawned executable to finish its
work. It always exits immediately. If you need to wait for the DOS
application to finish, then you need to use WaitForSingleObject(), or
GetExitCodeProcess() in a loop. For example:
if( CreateProcess(...) )
{
CloseHandle(piProcInfo.hThread);
WaitForSingleObject(piProcInfo.hProcess, INFINITE);
CloseHandle(piProcInfo.hProcess);
}
Or:
if( CreateProcess(...) )
{
CloseHandle(piProcInfo.hThread);
DWORD dwExitCode;
while( GetExitCodeProcess(piProcInfo.hProcess, &dwExitCode) )
{
if( dwExitCode != STILL_ACTIVE )
break;
Sleep(1000);
}
CloseHandle(piProcInfo.hProcess);
}
| Quote: | I don't know whether it is feasible to send you relative files to
you(bslw200 and so on), maybe you can see my problem more clearly.
|
That will not be necessary.
Gambit |
|
| Back to top |
|
 |
lackner Guest
|
Posted: Fri Mar 09, 2007 9:11 am Post subject: Re: How to run aonther application in current running applic |
|
|
hello Lebeau:
Actually, it doesn't work with CreateProcess(
NULL,
"f:\\bslw200.exe -b 38400 -r sbu410.hex",
NULL,
NULL,
0,
0,
NULL,
NULL,
&siStartInfo,
&piProcInfo);
there is no console open, The bslw200 command can't be execute. when
bslw200 is executing, it will look into Serial interface and wait for a
response from other component in our system, the timeout period of waiting
is quite long.
I don't know whether it is feasible to send you relative files to
you(bslw200 and so on), maybe you can see my problem more clearly.
Thanks you very much for your answer.
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> 写入消息新闻
:45f0d50e$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"lackner" <xubo (AT) bbn (DOT) cn> wrote in message
news:45f0cfd6 (AT) newsgroups (DOT) borland.com...
since my addtional application is a command line
application(bslw200.exe)
So? Every win32 application has a command line available. You can
run an application without caring whether it requires a console or
not.
it needs dos shell to run it.
A DOS console will be created automatically when CreateProcess() tries
to run a console application. The console will be freed after the
console application exits. So what exactly are you having a problem
with?
AnsiString strCmd = AnsiString("c:\\windows\\system32\\cmd.exe /c
start ");
You don't need that. The OS already know which command processor to
use. You can run bslw200.exe directly instead, ie:
STARTUPINFO siStartInfo = {sizeof(STARTUPINFO), 0};
PROCESS_INFORMATION piProcInfo = {0};
CreateProcess(
NULL,
"f:\\bslw200.exe -b 38400 -r sbu410.hex",
NULL,
NULL,
0,
0,
NULL,
NULL,
&siStartInfo,
&piProcInfo);
I don't know what wrong with it.
You did not say why you think anything is wrong.
Gambit
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|