Link to home
Start Free TrialLog in
Avatar of gvector1
gvector1

asked on

FTP

I have a C++ application that uses ftp to pull data to the local machine for processing and displaying.  I execute the ftp process by using spawnlp to start ftp and run a file containing all of the ftp commands.  Everything works fine except for a little display issue.  Whenever ftp is fun, all of the ftp commands are displayed in the command window that the application is currently running in.  It displays all of the commands that exist in the file passed to ftp.  Is there any way to run ftp without having the commands displayed?????????

Thanks,
kendal
Avatar of jkr
jkr
Flag of Germany image

>>Is there any way to run ftp without having the commands displayed?

You can run it even completely hidden, using

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd, BOOL bHide)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                           msg;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   bHide ? SW_HIDE : SW_SHOWNORMAL;

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                   &pi.hProcess,
                                                                   FALSE,
                                                                   INFINITE,
                                                                   QS_ALLINPUT
                                                               )
           )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);
}

and call it like

ExecuteAndWaitForCompletion ( "ftp.exe <cmdfile>", TRUE);

Or, if you don't have to wait for the program to finish,

WinExec ( "ftp.exe <cmdfile>", SW_HIDE);

will do also.
Avatar of gvector1
gvector1

ASKER

I just recently was able to try the recommendations and they work wonderful, but the ftp commands from the <cmdfile> are still echoing in the calling dos window.  The dos window is used to run the application before and after the call.  It is just that when ftp is called, the commands are echoed on the screen.  Once finished, the dos window displays new results.  The echoing commands is just a bothersome thing.  Any other suggestions on how to get rid of this?????

Thanks,
Kendal
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks jkr,
Once again you have come to my rescue.  That worked great.  

Thanks again,
Kendal