Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
@mtndesign In the future, please check the code formatting, you also have to remove the `backticks`. Thanks. – slhck Dec 3 '12 at 8:31
up vote 1 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.