Solved

Problem with VC++

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 96
notReplace  challenge 53 151
viewing source code from eclipse 13 110
EvenOdd challenge 10 148
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

696 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