Solved

Problem with VC++

Posted on 1998-08-11
3
187 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
sum28 challenge 31 115
twoTwo  challenge 35 107
Annoying "thing" blocks my view 4 114
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

790 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