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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.