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.
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.
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.
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.
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.
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.
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.
Correct.
What platform are you on? In what language are you trying to express a zero byte?
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.
So it was a null byte after all, right? Can you confirm by looking at the hex dump of your input?
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.
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.