Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write file from stdin and exit #196

Open
manix opened this issue Aug 20, 2022 · 0 comments
Open

Write file from stdin and exit #196

manix opened this issue Aug 20, 2022 · 0 comments

Comments

@manix
Copy link

manix commented Aug 20, 2022

Hello,

I have a rather unique case where I'd like to write a file to the Pico without first saving it on my local filesystem.

For this purpose I added a fairly simple new command wstdinf, which reads stdin and writes it to a file on the Pico, supposedly:

class Shell(cmd.Cmd):
    ...

    def do_wstdinf(self, line):
        [ filename ] = self.line_to_args(line)
        src_file = io.StringIO("")
        filesize = 0
        for line in sys.stdin:
           src_file.write(line)
           filesize += len(line)
    
        dst_dev, dst_dev_filename = get_dev_and_path(filename)
    
        # Copying from host to remote
        dst_dev.remote(recv_file_from_host, src_file, dst_dev_filename,
                              filesize, xfer_func=send_file_to_remote)
    
    ...

I test it with the following command

$ echo -e "wstdinf /pyboard/print.py\nprint('test')\n" | rshell 
Connecting to /dev/ttyACM0 (buffer-size 512)...
Trying to connect to REPL  connected
Retrieving sysname ... rp2
Testing if sys.stdin.buffer exists ... Y
Retrieving root directories ... /test.py/
Setting time ... Aug 20, 2022 13:42:15
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 1970
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/home/xxx> /dev/ttyACM0 closed
/home/xxx> 

After which any subsequent executions of rshell are unsuccessful:

$ rshell 
Connecting to /dev/ttyACM0 (buffer-size 512)...
Trying to connect to REPL 

If I unplug and plug in the usb again, I see that the file is created, but is empty:

/home/xxx> ls -la /pyboard/
     0 Jan  1 1970  print.py
  7293 Aug 20 02:30 test.py

It's probably something small that I'm missing but I've spent upwards of a few hours on this already and I'd really appreciate any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant