Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send file contents to GNU screen session?

I'm connecting to a development board over a serial port like so..

$ screen /dev/ttyUSB0 9600

I'm connected to a boot loader now, and it is asking me to send a file in srec format. I have the file, but how can I send it over the screen session?

like image 660
Anthony Green Avatar asked Nov 25 '13 19:11

Anthony Green


1 Answers

Hopefully you have already solved this problem yourself, but I'll answer in case anyone else have the same problem.

GNU screen has a command called readreg which you can use to read a file into a register. After a register is filled with data you can paste that data using the paste command.

Inside screen

Inside screen you press Ctr + a and then : to execute a command. Then you simply write and press enter:

readreg p /path/to/thefile

After you have executed the command you should se a message saying Slurped X character into buffer.

You can then paste the data in that buffer by again pressing Ctr + a and then :, then write and press enter:

paste p

Note: p is the name of the register

And you're done.

Outside screen

You could also execute the commands outside the screen session using the -X option. If you have a screen session named "ucontroller" which is attached to your serial port you can send the commands by executing:

screen -S ucontroller -X readreg p /path/to/thefile
screen -S ucontroller -X paste p

More resources

The information I have provided is taken directly from the man pages of screen(1), here is the relevant part of the man page:

readreg [-e encoding] [register [filename]]

Does one of two things, dependent on number of arguments: with zero or one arguments it it duplicates the paste buffer contents into the register specified or entered at the prompt.

With two arguments it reads the contents of the named file into the register, just as readbuf reads the screen-exchange file into the paste buffer. You can tell screen the encoding of the file via the -e option. The following example will paste the system's password file into the screen window (using register p, where a copy remains):

C-a : readreg p /etc/passwd

C-a : paste p

like image 180
rzetterberg Avatar answered Oct 21 '22 21:10

rzetterberg