Menu

Batch sset /P problem

2021-07-21
2021-07-26
  • Alan Darlington

    Alan Darlington - 2021-07-21

    Sorry if this is the wrong forum but I wanted to execute a cobol program based on input from the cmd process. Included in the cmd stream was set /P to obtain the name of the program. When I enter the info & press enter the cmd exits.
    Simple example:

    echo off
    set actn=d
    echo actn is %actn%
    set /P actn="Enter letter "
    echo actn now %actn%
    

    I expected that running this would allow me to enter a letter & press enter then display it, instead it simply terminates after pressing enter without the subsequent display of the entered letter.

     

    Last edit: Simon Sobisch 2021-07-21
  • Simon Sobisch

    Simon Sobisch - 2021-07-21

    That's likely the wrong forum, I've moved that to the more general help forum.

    It simply terminates because there is nothing in that prevents that. You may use a pause at the end for tests like this - or directly execute it from the cmd.exe to see the result - the display is just too fast.

     
    • Alan Darlington

      Alan Darlington - 2021-07-21

      Thanks Simon.  Your explanation is obvious once I think about it, just didn't see it for what it, in retrospective, obviously is.

      Thanks also for moving it.  I'm new to the forum & am having some difficulty finding my way round -- I'm an old machine code man from the early 60s and find these modern new-fangled machines difficult!

      Alan Darlington

       

      Last edit: Simon Sobisch 2021-07-21
    • Alan Darlington

      Alan Darlington - 2021-07-21

      Simon,
      Can you help me?  When I log on to sourceforge I go to
      https://sourceforge.net/.  How do I get from there to post or view a
      discussion thread or to change from one forum to another?  (I somehow
      managed to post the one discussion you answered but I've no idea how I
      got there).

      I have another item I'd like to post on General (though you could answer
      it here to avoid my embarrassment):   Why does this not work:

          echo off
          set actn= 1
          echo step 1
          if  %actn% equ  1
               echo step 2
          echo step 6
          pause
      

      the problem is the if statement but I don't know what is wrong with it. 
      Without the if it produces the expected step1, step 2 & step6 displays,
      with the if it doesn't reach the pause so just flashes the a screen at
      me (like my previous question).

      Thanks
      Alan Darlington

       

      Last edit: Simon Sobisch 2021-07-22
      • Simon Sobisch

        Simon Sobisch - 2021-07-22

        Looks like you want to go to https://sourceforge.net/p/gnucobol/discussion/

        Note: when answering to items on SF that you've subscribed to (you can turn that globally / per item on/off) those get posted to the item as answer - and each of those mails have a link to the item in it, so you can get there fast.

         
  • Anonymous

    Anonymous - 2021-07-22

    Some minor changes :

    rem echo off
    set actn=1
    echo step 1
    rem if %actn% equ 1
    if %actn%==1
      echo step 2
    echo step 6
    pause 
    

    CMD script is crude and cumbersome, on Win rarely used now days.

    I would recommend you try busybox-w32.
    This gives you the power of BASH, a UNIX shell script, on the Win platform.

     
  • Alan Darlington

    Alan Darlington - 2021-07-23

    Found the answer -- the problem is the if statement. the action to be taken (echo step 2) must appear on the same line as the if (though one could use just an open bracket on that line & closing after the echo step 2 on the next). (The changes made by anonymous still cause failure - at least on my system.) (If you type it in one line at a time into cmd you get a syntax error when you type in the if %actn%==1.)

    I still have not found out how to change forums or to add a new discussion -- help please.

     
    • Anonymous

      Anonymous - 2021-07-24

      Using WINE, I did a test run without any errors.

      New code :

      >./w01.bat
      
      >rem echo off 
      
      >set actn=1 
      
      >echo step 1 
      step 1
      
      >rem if 1 equ 1 
      
      >if 1==1 
      
      >echo step 2 
      step 2
      
      >echo step 6 
      step 6
      
      >rem pause  
      

      Your original code with echo on :

      >./w02.bat
      >rem echo off 
      
      >set actn= 1 
      
      >echo step 1 
      step 1
      
      >if   1 equ  1 
      
      >echo step 2 
      step 2
      
      >echo step 6 
      step 6
      
      >rem pause 
      

      No idea why you are getting syntax errors.
      What OS are you using.

      This language dates back to the old PC-DOS days, and is rarely used now days.
      It is really just a poor attempt to implement a UNIX like shell language, such as BASH, on DOS.

      A web search on 'dos command tutorial' yields Topic: MS-DOS Tutorial among others.

       
  • Simon Sobisch

    Simon Sobisch - 2021-07-23

    On the menu at the top (below the logo) you can access the different "tools"; some of those have multiple sub-tools like the tickets.
    On the left you find the menu for the current "tool", in this case the different forums to browse, and also the option to search all forums and to create a new topic.

     
  • Alan Darlington

    Alan Darlington - 2021-07-25

    In one of the responses Simon moved my question to the general forum. But I don't see a 'general' forum listed in the left hand panel -- how do I access it?

     
    • Arnold Trembley

      Arnold Trembley - 2021-07-26

      There are only four forums that I know of, and they are named "Help Getting Started", "GnuCOBOL", "Contributions", and "The Lounge".

      I'm not sure which one Simon means by "general", but it's easy to check all four forums. "Help Getting Started" and "Contributions" seem to have fairly specific purposes.

       
    • Simon Sobisch

      Simon Sobisch - 2021-07-26

      The "general help" forum I've referenced is the "Help getting started" one.

       

Anonymous
Anonymous

Add attachments
Cancel