Solved

FTP

Posted on 2004-08-24
4
227 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
[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
  • 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 500 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 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