Search code examples
shelldospipe

Using pipe symbol and "print" in Windows


I am trying to make a shell script work in Windows. Sorry but I'm not very experienced in Windows (or even that much in shell to be honest). The script works well except for this one line:

print "9\n0\n1\n5\n0\n0\n\n" | /usr/ts23/mm_util

The mm_util is an interactive utility that takes numbers as input. It chooses selection 9 first, then 0, then 1, etc. I've changed the path to use the utility, which has an identical interface in Windows but the output is just the first screen. The "9" input isn't entered, and because of this the output (that is parsed) is incorrect. How can I change this so that the "9" is entered on the first screen?


Solution

  • Here is a method that does not require a file. It works on the command line:

    (for %N in (9 0 1 5 0 0 "") do @echo(%~N)|c:\Users\ts23\mm_util
    

    The "" is to get an empty line in the output, as you had in your original question. Your answer does not have the blank line.

    The %~N notation strips enclosing quotes from the value.

    The echo( is non-intuitive syntax that can reliably print a blank line, in case %~N expands to nothing.

    Don't forget to double the percents if you put the code in a batch script.