escaping - Escape a console string containing a path with "\r" (python)

I need to send the following commands to a busybox device via a serial port:

SBC1000 > setenv serverip ''
SBC1000 > setenv fsfile '1k\root.jffs2-128k'
SBC1000 > saveenv

I can escape the single quotes of the first line without a problem using a backslash:

cmd = 'setenv serverip \'\''

I've tried various combinations of backslashes for the second line, but couldn't get the 1k\root part to escape properly. I believe it is being interpreted as a return. I tried double and triple escape with no success.

I finally stumbled upon using

cmd = 'setenv fsfile \'1k\\\u0072oot.jffs2-128k\''

to include the \r ( not a return ) for my string.

Is there a more readable way to include this \r ( not a return ) pattern in my string?

1 Answer

  1. Gavin- Reply


    The solution was to use double-quotes " " as suggested by John Szakmeister.

    I discovered that the command string was being passed to a function inside a private class based on pexpect-serial.

    My guess is that my string was being evaluated by pexpect in a greedy way. By using a distinct delimiter, the problem was overcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>