none
Cleanup the previous command line from command prompt. RRS feed

  • Question

  • Hi, 

    For my application I'm accepting the input parameters from command line. My requirement is, clean up the command line after processing so that user can not see the previous command in command history. 

    I want to  programmatically do this is C++. Is there any way ?

    Thanks In advance. 


    Nandkumar T.

    Monday, August 26, 2019 6:48 AM

All replies

  • Hi, 

    For my application I'm accepting the input parameters from command line. My requirement is, clean up the command line after processing so that user can not see the previous command in command history. 

    I want to  programmatically do this is C++. Is there any way ?

    Thanks In advance. 


    Nandkumar T.

    Sorry, I don't really understand. If you let the user start the app through command line, then he knows his input. Why don't you want the user see his call again?

    You could clear the console:

    http://www.cplusplus.com/articles/4z18T05o/

    https://stackoverflow.com/questions/6486289/how-can-i-clear-console

    Or use SetConsoleHistoryInfo with buffer size 0: https://docs.microsoft.com/en-us/windows/console/setconsolehistoryinfo

    Regards, Guido


    Monday, August 26, 2019 7:02 AM
  • Hi, 

    Thanks for response. My understanding was, command line details goes in command history and if my command has some confidential data (e.g. password) other process can access the details (I might completely wrong)

    Is there any way other that above API using which I can clear the commands from history ? 


    Nandkumar T.

    Tuesday, August 27, 2019 6:24 AM
  • Hi,

    Thank you for posting here.

    >>Is there any way other that above API using which I can clear the commands from history ? 

    I suggest you could try to use SetConsoleHistoryInfo function to set the history settings for the calling process's console. CONSOLE_HISTORY_INFO structure contains information about the console history.The HistoryBufferSize parameter refers to the number of commands kept in each history buffer.I suggest you could try setting it to 0.

    Best Regards,

    Jeanine Zhang

    Tuesday, August 27, 2019 8:32 AM
    Moderator
  • Hi Jeanine, 

    Because of some reason I can not use SetConsoleHistoryInfo function. Is there any way to pass the password as command line argument secretly to the application in windows? My intention is to execute the application with command line parameters through the script and password shouldn't display in console history. 




    Nandkumar T.


    • Edited by Nandkumar T Wednesday, August 28, 2019 5:13 AM
    Wednesday, August 28, 2019 5:12 AM
  • Because of some reason I can not use SetConsoleHistoryInfo function. Is there any way to pass the password as command line argument secretly to the application in windows? My intention is to execute the application with command line parameters through the script and password shouldn't display in console history. 


    A command line Parameter is Always shown because the user must write it. It cannot be "hidden".

    Passing a password through command line parameter is the wrong attempt. Use a flag like "-p" and let the user type in the passwort after execution. (Have a look at mysql command for example).

    If you cannot use SetConsoleHistoryInfo, then IMO there is no way.

    Regards, Guido

    Wednesday, August 28, 2019 5:55 AM
  • Hi,

    Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Jeanine Zhang

    Monday, September 2, 2019 2:19 AM
    Moderator