@@ -253,17 +253,16 @@ def main():
253253 cmd_parser .add_argument ('-b' , '--baudrate' , default = 115200 , help = 'the baud rate of the serial device' )
254254 cmd_parser .add_argument ('-u' , '--user' , default = 'micro' , help = 'the telnet login username' )
255255 cmd_parser .add_argument ('-p' , '--password' , default = 'python' , help = 'the telnet login password' )
256+ cmd_parser .add_argument ('-c' , '--command' , help = 'program passed in as string' )
256257 cmd_parser .add_argument ('--follow' , action = 'store_true' , help = 'follow the output after running the scripts [default if no scripts given]' )
257258 cmd_parser .add_argument ('files' , nargs = '*' , help = 'input files' )
258259 args = cmd_parser .parse_args ()
259260
260- for filename in args . files :
261+ def execbuffer ( buf ) :
261262 try :
262263 pyb = Pyboard (args .device , args .baudrate , args .user , args .password )
263264 pyb .enter_raw_repl ()
264- with open (filename , 'rb' ) as f :
265- pyfile = f .read ()
266- ret , ret_err = pyb .exec_raw (pyfile , timeout = None , data_consumer = stdout_write_bytes )
265+ ret , ret_err = pyb .exec_raw (buf , timeout = None , data_consumer = stdout_write_bytes )
267266 pyb .exit_raw_repl ()
268267 pyb .close ()
269268 except PyboardError as er :
@@ -275,7 +274,15 @@ def main():
275274 stdout_write_bytes (ret_err )
276275 sys .exit (1 )
277276
278- if args .follow or len (args .files ) == 0 :
277+ if args .command is not None :
278+ execbuffer (bytes (args .command , 'utf-8' ))
279+
280+ for filename in args .files :
281+ with open (filename , 'rb' ) as f :
282+ pyfile = f .read ()
283+ execbuffer (pyfile )
284+
285+ if args .follow or (args .command is None and len (args .files ) == 0 ):
279286 try :
280287 pyb = Pyboard (args .device , args .baudrate , args .user , args .password )
281288 ret , ret_err = pyb .follow (timeout = None , data_consumer = stdout_write_bytes )
0 commit comments