0

In Linux bash I could pass python-printed string as a parameter to my program and it looked like this my_program $(python -c "print('A'*100)")

Is there a way to do the same in Windows CMD?

AϟϟTERIX
  • 109
  • 3
  • 13
  • No, but you can run the python program from a `for /f` loop and parse the output. If `A` represents a variable from the batch it should be written `%A%` –  Nov 26 '16 at 20:55
  • Is `'A'*100500` a real example? See [What is the maximum length of an environment variable?](https://blogs.msdn.microsoft.com/oldnewthing/20100203-00/?p=15083) – JosefZ Nov 26 '16 at 22:34
  • @JosefZ just fixed that – AϟϟTERIX Nov 26 '16 at 22:36
  • 1
    Possible duplicate of [Batch - Assign Command output to Variable](http://stackoverflow.com/questions/16203629/batch-assign-command-output-to-variable) – JosefZ Nov 26 '16 at 22:45
  • A batch `for /f` loop executes the loop body for every line in the file or command output, but bash instead collapses white space (spaces, tabs, newlines) in the output to a space-delimited string in which quotes are literals. To approximate this in cmd, you could join lines with spaces, e.g. `set "args="` `& (for /f "usebackq delims=" %i in (\`python -c "print('A\n' * 100)"\`)` `do @(if defined args (set "args=!args! %i") else (set args=%i)))` `& my_program !args!`. But this doesn't translate tabs to spaces or escape double quotes as literals. – Eryk Sun Nov 27 '16 at 08:23
  • @eryksun thanks. That helped – AϟϟTERIX Nov 27 '16 at 09:59

0 Answers0