Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FTP

Posted on 2004-08-24
4
Medium Priority
?
232 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:gvector1
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11884482
>>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.
0
 

Author Comment

by:gvector1
ID: 11946549
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
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 11946597
If you are using 'ExecuteAndWaitForCompletion ()', change the 'CreateProcess()' call to read

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, // <---!
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

and you should get rid of the problem.
0
 

Author Comment

by:gvector1
ID: 11996497
Thanks jkr,
Once again you have come to my rescue.  That worked great.  

Thanks again,
Kendal
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

972 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