Solved

eVC: Starting other app and writing a file

Posted on 2006-10-19
10
174 Views
Last Modified: 2013-11-20
Hello

embeddedVisual C++-QUESTION!

I'm normally a .NET-Coder für CF, so I am kind'a new to eVC.
I need a very small application which only function is:

Start
executing another application
writing a string "done" to a file in the same directory as the application
is
exiting...

in .NET it would be some few lines of code, but I just dont know enough C++
to do it in eVC...

If someone could give me the code for this, I would be veeeery happy and
thankful!

Sven
0
Comment
Question by:Ruttensoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17763884
>>in .NET it would be some few lines of code, but I just dont know enough C++ to do it in eVC...

   you may use CreateProcess() to start another appliation and wait for exit something like

        PROCESS_INFORMATION pi;
        CreateProcess( (_T("Process.exe"), NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi ); //Start Process... replace Process.exe with ur app path string
        WaitForSingleObject( pi.hProcess, INFINITE );
        CloseHandle(pi.hProcess);


// Now open file and write to file using CFile or CStdioFile MFC Class

-MAHESH
0
 

Author Comment

by:Ruttensoft
ID: 17763909
Thanks I will have a look at it. Where can I enter a comandline-string? at the first null?
Can it be just "-hello" or do I have to _T("-hello"), or something like that?
Sorry but I'm very new to C++...

Thanks
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 500 total points
ID: 17763932
You can input command line arguments to CreateProcess() function's 2nd parameter

e.g
CreateProcess(_T("App.exe"),_T("-Argument1 -Argument2")........

For more have a look at :
INFO: Understanding CreateProcess and Command-line Arguments :http://support.microsoft.com/kb/175986

-MAHESH
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ruttensoft
ID: 17763939
Thanks and how do I exit a eVC-App by code?
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17763955
what do you mean by exit a eVC-App by code ?

Above code given by me will start process wait for process execution and exit......and if you want to terminate started process at any time then remove WaitForSingleObject() function from above and you may use TerminateProcess () API

e.g

TerminateProcess(pi.hProcess,-1);

-MAHESH
0
 

Author Comment

by:Ruttensoft
ID: 17764014
Hi

Sorry for my unprecise question.
I want that the app does not wait until the started process has terminated. I want the app to terminate itself, the started process should not quit...

Thanks so much
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17764026
then that your application should take care of iteself to terminate usign exit() or so.....
but there is no difference if application exits itself or it terminate using WaitForSingleObject() / TerminateProcess()

-MAHESH
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
zeroMAx challenge 20 135
sumHeights2  challenge 7 140
Use of condition with 'serial' in ansible 2 102
My project did see openJDK that I installed. What could be the problem 7 172
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question