Solved

Problem with VC++

Posted on 1998-08-11
3
189 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
[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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

719 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