Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FTP

Posted on 2004-08-24
4
Medium Priority
?
231 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

670 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