CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2013
    Posts
    15

    How to read sentence from Command line with MFC?

    I want to read sentence from command line. I open some program which run in command line and I have to wait for that program process. So , I don't know when process success .I can't type next command if can't read sentence from command. I use
    Code:
     wprintf(GetCommandLine());
    but it show
    "C:\Users\PKRU\documents\visual studio 2010\Projects\Virus Scan\Debug\MyProgram
    please help me How to read sentence from Command line with MFC ?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to read sentence from Command line with MFC?

    There is a MFC class CCommandineInfo
    You may also want to look at this thread
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to read sentence from Command line with MFC?

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    
    int _tmain()
    {
    	_tprintf(GetCommandLine());
    	return 0;
    }
    Code:
    D:\Temp\80>cl 80.cpp /D"UNICODE" /D"_UNICODE"
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    80.cpp
    Microsoft (R) Incremental Linker Version 10.00.40219.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:80.exe
    80.obj
    
    D:\Temp\80>80.exe iuhbiub oiono
    D:\Temp\80\80.exe  iuhbiub oiono
    Best regards,
    Igor

  4. #4
    Join Date
    Feb 2013
    Posts
    15

    Re: How to read sentence from Command line with MFC?

    Thank you for answer. I use this code in VC

    int _tmain()
    {
    system("D:");
    _tprintf(GetCommandLine());

    getch();
    return 0;
    }

    but when I click run button it show "C:\Users\MAX\Documents\Visual Studio 2010\Projects\TestCmd\Debug\TestCmd.exe"

    I read CCommandineInfo the function ParseCommandLine can send parameter from command to MFC, But I want to know when my console process success and ask for send Y/N to command. If MFC can know when it ask Y/N ,then I can send char to process next command.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to read sentence from Command line with MFC?

    Quote Originally Posted by mmc01 View Post
    ... when I click run button it show "C:\Users\MAX\Documents\Visual Studio 2010\Projects\TestCmd\Debug\TestCmd.exe"
    And what command line parameters (exactly!) did you pass in?
    Victor Nijegorodov

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to read sentence from Command line with MFC?

    Quote Originally Posted by mmc01 View Post
    but when I click run button it show "C:\Users\MAX\Documents\Visual Studio 2010\Projects\TestCmd\Debug\TestCmd.exe"
    And what did you expect? This is exactly the command line your process has been run with. Do you have any idea what command line is? I wonder what sense that system("D:"); makes for you?

    I read CCommandineInfo the function ParseCommandLine can send parameter from command to MFC, But I want to know when my console process success and ask for send Y/N to command. If MFC can know when it ask Y/N ,then I can send char to process next command.
    You're trying to do something you have no idea about. You cannot program Windows without knowing how the very basic OS mechanisms work.

    When program exits it always provides exit code specific to the circumstances of termination. By the code value any outer process can tell if the exit was successful or not, and typically 0 means success (a UNIX/POSIX legacy). But the part about MFC knowing something and sending another something sounds totally gibberish. This is what you have to explain, if you want to be really helped.
    Last edited by Igor Vartanov; February 11th, 2013 at 01:17 PM.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured