Solved

Problem with VC++

Posted on 1998-08-11
3
183 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now