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

staticExec removes trailing LF which interferes with binary output that happens to end with 0xA #13786

Open
qbradley opened this issue Mar 28, 2020 · 4 comments · Fixed by #13813

Comments

@qbradley
Copy link

producing binary output using staticExec can get corrupted if the last byte of the binary data happens to be 0xA (LF)

Example

const compressed = staticExec("gzip -9 -c test.dat")
# compressed.len can be one byte short in case compressed data happens to end with 0xA
# which was in fact the case for a little file I created

Possible Solution

  • I understand how removing the trailing newline may be convenient in textual cases. Perhaps staticExec could optionally take a flag indicating that the output is binary, or make a new magic function that doesn't chop the LF.
$ nim -v
Nim Compiler Version 1.0.6 [Linux: amd64]
Compiled at 2020-01-23
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release
@qbradley
Copy link
Author

qbradley commented Mar 28, 2020

As a workaround, I'm using:

const ignored = staticExec("gzip -9 -c test.dat >/tmp/test.dat")
const compressed = staticRead("/tmp/test.dat")

@timotheecour
Copy link
Member

timotheecour commented Mar 31, 2020

unfortunately that's OS specific; see #13813 which offers a better way via simply letting you call execCmdEx (and pass whichever options to execCmdEx)

@Clyybber
Copy link
Contributor

Can we still fix staticExec to simply not remove the trailing newline?

@Araq Araq reopened this Apr 21, 2020
@Araq
Copy link
Member

Araq commented Apr 21, 2020

Let's give staticExec another default parameter.

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

Successfully merging a pull request may close this issue.

4 participants