How to work with CMD prompt and prompt selections

  • I have an executable that when ran opens a cmd windows, gives some information, and then prompts for a selection at the prompt as show below:

    "Would you like to proceed? [Y\N]"

    I am trying to figure out how best to program the automation of a response of Yes via PowerShell. I have looked at Invoke-Cmd but not getting how I can use this in the way that I need things to work.

    Any ideas?

    Thanks!

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • This will execute the application but as a result it opens in a cmd window and how to make the default selection of Y (Yes) from the window? Note, the executable doesn't take parameters as input.

    Start-Process -filePath "C:\DB Tools\DBCleaner\DbCleaner.exe"

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • It sometimes depends on the executable, but I've had good luck with this problem in the past.

    First, make a text file called Y.txt. It should contain 1 character. That character is "Y" without the quotes. Make sure that when you enter the character to press the [Enter] key after the "Y" in whatever editor you're creating the file in.

    Then, when you execute the exe, include a redirected input from the Y.txt file. From a command prompt, it would look like the following...

    C:\DB Tools\DBCleaner\DbCleaner.exe < C:\somepath\Y.txt

    ... where "C:\somepath\" is the actual folder that the Y.txt file lives in.

    I don't know if "Start-Process -filePath" will handle such redirection, though.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • That trick works with the exe that I just created will see if it works with the one I actually have to run it against. Thanks!

    Jeff Moden (5/26/2012)


    It sometimes depends on the executable, but I've had good luck with this problem in the past.

    First, make a text file called Y.txt. It should contain 1 character. That character is "Y" without the quotes. Make sure that when you enter the character to press the [Enter] key after the "Y" in whatever editor you're creating the file in.

    Then, when you execute the exe, include a redirected input from the Y.txt file. From a command prompt, it would look like the following...

    C:\DB Tools\DBCleaner\DbCleaner.exe < C:\somepath\Y.txt

    ... where "C:\somepath\" is the actual folder that the Y.txt file lives in.

    I don't know if "Start-Process -filePath" will handle such redirection, though.

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • Thanks for the feedback. I'd be interested in knowing if it actually works on the one you wanted it to. Let me know, if yhou get the chance.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I tried every way icould think of to get it to work with get-process but no luck. I will let you know once i confirm.

    Jeff Moden (5/27/2012)


    Thanks for the feedback. I'd be i[font=][/font]nterested in knowing if it actually works on the one you wanted it to. Let me know, if yhou get the chance.

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • Be advised that some of these apps just don't work this way. They sometimes require the human element to be present at just the right time.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • The only way we could get this to work was to add a flag to the program that bypasses the prompt. Logical because you can't tell a program to do something that it hasn't been written to do, and the only alternative to the prompt seemed to be to send a key stroke to the console once it was there. Not practical at all.

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • I sure do appreciate you taking the time for the feedbback here. As a side bar, what you just said makes me real happy that I walked away from the front end world back in 2002. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 🙂 I am thankful you appreciate it. It is all about the journey and learning out realistic limitation in it! Thank you for helping me along that journey!!

    Jeff Moden (5/31/2012)


    I sure do appreciate you taking the time for the feedbback here. As a side bar, what you just said makes me real happy that I walked away from the front end world back in 2002. 😉

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply