--from-file parameter NUL #172

Closed
opened 2023-07-30 10:26:05 +00:00 by jrennef · 2 comments

Hello,

I am working on a script that calls img2pdf to convert a bunch of files to pdf.
I would like to support filesnames with whitespaces. For this I tried different approaches quoting the filenames as positonal parameters and now I want to use the --from-file parameter and write the filesnames to a textfile.
However I don't know if am doing this right.

The paths to the input images in FILE are separated by NUL bytes

From my understanding the NUL is the ASCII Charater with Code 0. I tried to represent that char as \0 or `0 but that does not work.

/path/file name 1.jpg\0/path/file name 2.jpg\0

Finally I piped the output of find -print0 to a textfile. And the Char that shows up as separator is "¿" inverted question mark. Thats definetly not the NUL char.
When I use that with img2pdf it works.

/path/file name 1.jpg¿/path/file name 2.jpg¿

But I would like to understand why it works and if this really is the right way to do it?
Does someone have expirence using the --from-file parameter or can explain my observed behavior?
Thanks.

Hello, I am working on a script that calls img2pdf to convert a bunch of files to pdf. I would like to support filesnames with whitespaces. For this I tried different approaches quoting the filenames as positonal parameters and now I want to use the --from-file parameter and write the filesnames to a textfile. However I don't know if am doing this right. > The paths to the input images in FILE are separated by NUL bytes From my understanding the NUL is the ASCII Charater with Code 0. I tried to represent that char as \0 or `0 but that does not work. ``` /path/file name 1.jpg\0/path/file name 2.jpg\0 ``` Finally I piped the output of find -print0 to a textfile. And the Char that shows up as separator is "¿" inverted question mark. Thats definetly not the NUL char. When I use that with img2pdf it works. ``` /path/file name 1.jpg¿/path/file name 2.jpg¿ ``` But I would like to understand why it works and if this really is the right way to do it? Does someone have expirence using the --from-file parameter or can explain my observed behavior? Thanks.
Owner

From my understanding the NUL is the ASCII Charater with Code 0

Correct.

/path/file name 1.jpg\0/path/file name 2.jpg\0

What platform are you on? In what language are you trying to express a zero byte?

Finally I piped the output of find -print0 to a textfile. And the Char that shows up as separator is "¿" inverted question mark

Where does it show up as an inverted question mark? This might just be the way in which whatever viewer you are using displays a null byte.

When I use that with img2pdf it works.

So it was a null byte after all, right? Can you confirm by looking at the hex dump of your input?

But I would like to understand why it works and if this really is the right way to do it?

Using find -print0 is one of the ways to do it.

I need more information about what tools and what platform you are doing all of this with an on.

> From my understanding the NUL is the ASCII Charater with Code 0 Correct. > /path/file name 1.jpg\0/path/file name 2.jpg\0 What platform are you on? In what language are you trying to express a zero byte? > Finally I piped the output of find -print0 to a textfile. And the Char that shows up as separator is "¿" inverted question mark Where does it show up as an inverted question mark? This might just be the way in which whatever viewer you are using displays a null byte. > When I use that with img2pdf it works. So it was a null byte after all, right? Can you confirm by looking at the hex dump of your input? > But I would like to understand why it works and if this really is the right way to do it? Using `find -print0` is one of the ways to do it. I need more information about what tools and what platform you are doing all of this with an on.
Author

Thanks @josch for pointing me in the right direction.
I am on macOS 13 and I use Bash as well as PowerShell as Terminal/Scripting environment and BBEdit as Editor/Viewer.
You are absolutely right, BBEdit displays the NUL Char as ¿.
When I view the text file in Terminal via more is shows ^@ instead.
I also looked at a hex dump of the text file and it sure is 00.

In my powershell script I tried to use `0 as escape sequence for NUL in strings and it did not work when handing it to img2pdf as a cmdline parameter.
But when I write it to a text file and point img2pdf to that textfile with --from-file it works now.
So thanks again, this helped a lot.

Thanks @josch for pointing me in the right direction. I am on macOS 13 and I use Bash as well as PowerShell as Terminal/Scripting environment and BBEdit as Editor/Viewer. You are absolutely right, BBEdit displays the NUL Char as ¿. When I view the text file in Terminal via more is shows ^@ instead. I also looked at a hex dump of the text file and it sure is 00. In my powershell script I tried to use `0 as escape sequence for NUL in strings and it did not work when handing it to img2pdf as a cmdline parameter. But when I write it to a text file and point img2pdf to that textfile with --from-file it works now. So thanks again, this helped a lot.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#172
No description provided.