Solved

Problem with VC++

Posted on 1998-08-11
3
184 Views
Last Modified: 2013-11-20
I wrote a program who must read from a file a path from an executable program and execute it .
This is:

#include <stdio.h>
#include <process.h>
...
      FILE *f;
      char  s[100];
      f=fopen("c:\\file.txt","r");   //in file.txt is the path (let say it is "C:\\prg.exe")
      fscanf(f,"%s",s);
      fclose(f);
      _spawnlp(_P_NOWAIT,s,s,0); //should execute the program prg.exe

I compiled this in Borland 4.5 and it works
When I compiled this in VC++ 5.0 wouldn't work ( the program doesn't respond (in Windows 95))
Can somebody give me an example of a correct code ?
0
Comment
Question by:pasare
  • 2
3 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1320620
For Win32 applications, use the CreateProcess function instead of _spawnlp.

STARTUPINFO StartupInfo =
{
    sizeof(STARTUPINFO),
    NULL,
    NULL,
    NULL,
    0, 0,
    0, 0,
    0, 0,
    0,
    STARTF_USESHOWWINDOW,
    SW_SHOW,
    0,
    NULL,
    NULL,
    NULL,
    NULL
};
PROCESS_INFORMATION ProcessInformation;
BOOL bRetVal = ::CreateProcess(NULL,
                                             s,
                                             NULL,
                                             NULL,
                                             FALSE,
                                             0,
                                             NULL,
                                             NULL,
                                             &StartupInfo,
                                             &ProcessInformation);
if (bRetVal)
{
    ::CloseHandle(ProcessInformation.hProcess);
    ::CloseHandle(ProcessInformation.hThread);
}

0
 

Author Comment

by:pasare
ID: 1320621
Still doesn't work. I suggest you to try it .
However if I call _spawnlp(_P_NOWAIT,"c:\\prg.exe","c:\\prg.exe",0) this works but when
I read from a file the string, won't work . I debug the program and the string s  is "c:\\prg.exe" ( reading  from file is executed well ) .
0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1320622
I guess you wrote "c:\\prg.exe" in the text file. The double '\' is only needed for C++ source code since '\' is an escape character. Write "c:\prg.exe" in the text file.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 79
Process filename extension 3 172
How to determine file rename from EventLog ? 2 41
Change to event 1 101
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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now