none
Need help with CMD prompt

    Question

  • Can anyone help me I have limited knowledge of VS and here is my problem :

    Outside of VS i have a batch file which runs some diagnostics for me on another device. What normally happens is when I  run it it opens the command prompt and populates it with a password prompt when the password is entered it runs the script.

    What I want to do is :

    I have now created a form which four buttons on (one for each script i have) and when button is pushed it runs the script .

    I have managed to get VS to open the command promt and the password prompt is sitting there waiting ,however when i put the password in the command prompt closes and does not seem to do any thing ,anyone have any ideas please

    Tuesday, August 09, 2016 5:44 PM

Answers

  • Hi,

    as someone said already: It is quite likely that the Run_me* scripts are simply not found.

    If they are inside the same directory as the script that you started, then you could use %~dp0 which holds the directory of the current script.

    So the Script could be changed to:

    @echo off
    set PW=
    set /P PW=Enter password: %=%
    if defined PW if "%PW:~10,1%"=="" goto oldversion
    cls
    %~dp0Run_me_v8.bat %pw% > resultsv8.txt
    :oldversion
    cls
    %~dp0Run_me_v18.bat %pw% > resultsv18.txt

    There is no \ between the %~dp0 and the following command because that is already included in this special variable.

    With kind regards,

    Konrad

    Thursday, August 11, 2016 9:32 AM
    Moderator

All replies

  • What is the scripting language?  How does the batch file launch the script?  How does the batch file display the password prompt?
    Tuesday, August 09, 2016 5:50 PM
  • Hi

    They were created in psexec i have tried dd pasting the files but does not work so i have copied the text

    @echo off
    set PW=
    set /P PW=Enter password: %=%
    if defined PW if "%PW:~10,1%"=="" goto oldversion
    cls
    Run_me_v8.bat %pw% > resultsv8.txt
    :oldversion
    cls
    Run_me_v18.bat %pw% > resultsv18.txt

    Tuesday, August 09, 2016 6:16 PM
  • How did you launch the command prompt & batch file from your form?  (and Which .NET language are you using?)

    Is it possible that you redirected your standard input when you executed your shell command as opposed to leaving standard input so that it comes from the user?

    Tuesday, August 09, 2016 6:43 PM
  • Maybe it does not find your secondary .BAT files. Then you should select the right current directory before starting the script. It depends on your technique.

    To debug the problem, try putting some echo and pause statements inside the script. For example, add the line echo Starting old version && pause after the :oldversion line, etc.




    • Edited by Viorel_MVP Tuesday, August 09, 2016 6:50 PM
    Tuesday, August 09, 2016 6:47 PM
  • Thanks for your help 

    the batch file launches the command promt as bat files only run inside that window and i just put a button on a form and used this command

     Shell("C:\Users\steve\Desktop\run_me.bat")  

    and you are right i dont think it finds the next bat file which is named run_me_v8.bat

    @echo off
    for /F %%A in (All_v8.txt) do @error_v8.bat %%A %1


    Tuesday, August 09, 2016 6:58 PM
  • You can ChDir to the C:\Users\steve\Desktop folder then Shell run_me.bat.  That should set the working folder.

    Tuesday, August 09, 2016 7:08 PM
  • I apologise for my ignorance but could you write me an example of what i should be writing
    Tuesday, August 09, 2016 7:24 PM
  • Thanks for Wyck and Viorel_'s help.

    Hi Steve5915,

    >>I have managed to get VS to open the command promt and the password prompt is sitting there waiting

    Could you provide a screen shot about the above result?

    Actually this forum is to discuss the VS IDE usage, if possible, please share us the detailed called order in your side:

    For example, I write a bat file which called the MSTest.exe, the mstest.exe will run a test in command line, and then I call the bat file in a winform app, if I got an issue during I run the winform app, I need to narrow down this issue.

    (1) Run the MSTest.exe in command line singly.

    (2) Run the Bat file.

    (3) Run the winform app.

    And then we could know that whether it is related to the bat script or the mstest or the test method or the winform app.

    So the same steps, if it has an issue in your side, we have to make sure that which steps really generate this issue firstly, and then we could provide you a correct path or useful information.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 11, 2016 9:26 AM
    Moderator
  • Hi,

    as someone said already: It is quite likely that the Run_me* scripts are simply not found.

    If they are inside the same directory as the script that you started, then you could use %~dp0 which holds the directory of the current script.

    So the Script could be changed to:

    @echo off
    set PW=
    set /P PW=Enter password: %=%
    if defined PW if "%PW:~10,1%"=="" goto oldversion
    cls
    %~dp0Run_me_v8.bat %pw% > resultsv8.txt
    :oldversion
    cls
    %~dp0Run_me_v18.bat %pw% > resultsv18.txt

    There is no \ between the %~dp0 and the following command because that is already included in this special variable.

    With kind regards,

    Konrad

    Thursday, August 11, 2016 9:32 AM
    Moderator
  • Hi Stenve5915,

    Have you followed Konrad's script? how about sharing your solution and result here.

    If you think Konrad's reply is helpful, please mark his reply as the answer, it will benefit to other community members who have the same issue. It will be easier for them to search the solution.

    Have a nice day!

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click HERE to participate the survey.

    Wednesday, August 17, 2016 3:02 AM
    Moderator