system() function that does not pop up a dos box

I've inherited some code that has system() function calls. It
works but a dos box pops up for a fraction of a second and it
looks crummy. There must be a better way to do this. Any
suggestions? I'm on NT4, VC++ 4.2 and 5.

Thanks!

Dave
esdaveAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
Use CreateProcess with SW_HIDE.

STARTUPINFO StartupInfo =
{
    sizeof(STARTUPINFO),
    NULL,
    NULL,
    NULL,
    0, 0,
    0, 0,
    0, 0,
    0,
    STARTF_USESHOWWINDOW,
    SW_HIDE,
    0,
    NULL,
    NULL,
    NULL,
    NULL
};

PROCESS_INFORMATION ProcessInformation;

if (::CreateProcess(NULL,
                    _T("prg.exe"),
                    NULL,
                    NULL,
                    TRUE,
                    0,
                    NULL,
                    NULL,
                    &StartupInfo,
                    &ProcessInformation))
{
    ::CloseHandle(ProcessInformation.hProcess);
    ::CloseHandle(ProcessInformation.hThread);
}
0
 
esdaveAuthor Commented:
Well heck. It looked like it would work but I've done something wrong. Just as a test I did the following. Do you see anything wrong???

Thanks!

Dave

void CVTestDlg::OnCreateprocessCall()
{
      // TODO: Add your control notification handler code here


      STARTUPINFO StartupInfo =
    {
     sizeof(STARTUPINFO), NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0,
     STARTF_USESHOWWINDOW, SW_HIDE, 0,
     NULL, NULL, NULL, NULL
    };

    PROCESS_INFORMATION ProcessInformation;

    if (::CreateProcess(NULL, _T("dir c: > c:\junk"), NULL, NULL, TRUE, 0, NULL, NULL, &StartupInfo, &ProcessInformation))
    {
      ::CloseHandle(ProcessInformation.hProcess);
      ::CloseHandle(ProcessInformation.hThread);
    }
0
 
chensuCommented:
But you've got to tell me what you have seen. Any error messages?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
esdaveAuthor Commented:
The file that I expected to be created (c:\junk") wasn't created. I'll try to retrieve the error message.

dave
0
 
esdaveAuthor Commented:
I think I'm getting



Error 2 - The system cannot find the file specified.

I can't say that I understand this...
0
 
chensuCommented:
_T("dir c: > c:\\junk")
0
 
esdaveAuthor Commented:
I think I'm getting



Error 2 - The system cannot find the file specified.

I can't say that I understand this...
0
 
chensuCommented:
Dir is an internal command.

_T("start dir c: > c:\\junk")

or

_T("command /cdir c: > c:\\junk")    // Windows 9x

_T("cmd /cdir c: > c:\\junk")    // Windows NT
0
 
esdaveAuthor Commented:
Using GetLastError I get the same error with the \\
0
 
chensuCommented:
Dir is an internal command.

_T("start dir c: > c:\\junk")

or

_T("command /cdir c: > c:\\junk")    // Windows 9x

_T("cmd /cdir c: > c:\\junk")    // Windows NT
0
 
esdaveAuthor Commented:
Ok... that did the trick. My final question is where do I find the "commands" that I can use? I want to mkdir, copy, delete, and other "system" type things that I have been using system() for.

Thanks!

dave P
0
 
esdaveAuthor Commented:
Ok... that did the trick. My final question is where do I find the "commands" that I can use? I want to mkdir, copy, delete, and other "system" type things that I have been using system() for.

Thanks!

dave P
0
 
esdaveAuthor Commented:
Thanks! I found everything I need...

Dave P
0
 
chensuCommented:
I would suggest you use the following Win32 API functions to do mkdir, copy, delete, ...

CreateDirectory
CopyFile
DeleteFile
SHFileOperation
....
0
All Courses

From novice to tech pro — start learning today.