0

I'm trying to write a batch file that will automatically run a python script. After python main.py is executed, the script asks for what serial port the user is using (using the raw input function in python).

I want to automatize the process by trying all the different COM ports until we find the correct port so users do not have to enter the COM port.

Basically I am just wondering what batch command is used to write to the terminal? I'm new to batch and I couldn't find any information about my specific question...

I have tried this so far:

    main.py
    echo COM3
    pause   

But the "COM3" does not get entered in to the terminal. Would really appreciate any help thanks so much!

Jennifer
  • 37
  • 5
  • `echo hi > COM3`. See a list of punctuation http://stackoverflow.com/questions/31820569/trouble-with-renaming-folders-and-sub-folders-using-batch –  Jul 13 '16 at 23:19
  • That really threw ME for a loop. I thought he was talking about RAW (non-canonized) input on a UNIX tty! – Bruce David Wilner Jul 14 '16 at 00:19

1 Answers1

0

Try a pipe, which directs the output of one command to the input of another:

echo COM3 | main.py

Ideally, however, your main.py would be written to take the port on the command line, instead of prompting for it (or only prompting if it's not found on the command line). Like this:

import sys

if len(sys.argv) < 2:
    port = raw_input("Enter port number: ")
else:
    port = sys.argv[1]

Then you can simply do main.py COM3.

kindall
  • 178,883
  • 35
  • 278
  • 309