Screen run command, detach and get output

3

I am trying write a script which connects and runs command on /dev/ttyUSB0 after that gets the output.

screen -d -m 'SCREEN COMMAND' -L /dev/ttyUSB0

But this does not create an output file. How can I solve this issue? Any ideas?

denizeren

Posted 2012-12-03T08:05:59.390

Reputation: 143

1@mtndesign In the future, please check the code formatting, you also have to remove the `backticks`. Thanks. – slhck – 2012-12-03T08:31:57.007

Answers

1

Try pyserial library of python. I think you can solve it with this library. You can find a tutorial in here

0xmtn

Posted 2012-12-03T08:05:59.390

Reputation: 140

0

screen is good to have your terminal session to run detached. However, it was not designed to automatically run commands on terminals.

For this purpose, another tool was developed - expect.

expect allows to script human-like interaction with programs running on terminal.

It is powerful tool, but it is also another scripting language to learn and can be a bit tedious. If you are familiar with Perl, Perl Expect module can save you a lot of effort (there are also expect modules for other scripting languages like Python).

One more note. In your case, it seems that /dev/ttyUSB0 is serial-over-USB device that may connect or disconnect at any time. If you want to automatically maintain interaction to this serial-over-USB interface, you may consider either watching for this device to appear/disappear and reconnect automatically (say in Perl script), or add udev rule (under /etc/udev/rules.d) which will automatically start your handler program as new USB device is connected.

mvp

Posted 2012-12-03T08:05:59.390

Reputation: 3 705