Stumbled by the filesystem in Rust

I'm writing a test to execute sql, but the spawned command just can't find the created files!

The code below reproduces the error via cat command:

I really don't know what's going on...

You are accidentally debug-escaping the format string in the .arg() of the Command. This works. (You probably confused shell-escaping with .arg()? Escaping doesn't happen here, you are literally passing the prepared arguments to the command, the shell has no say in it.)

1 Like

Thanks! I never knew that, and I was always thinking about checking the existence of files.

Now the error from cat is clearer to me than that from clickhouse...

// clickhouse error:
stderr = Code: 107. DB::ErrnoException: Cannot open file "/tmp/.tmp7AJJ9D/1-xxx/__full.sql", errno: 2, strerror: No such file or directory. (FILE_DOESNT_EXIST)

// cat error:
stderr = cat: '"/tmp/.tmp7AJJ9D/1-xxx/__full.sql"': No such file or directory

So the error can be reproduced in the simple case: Rust Playground LOL

And I read the arg signature again

pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command

then we can directly pass the path into it :laughing:

let output = Command::new("cat").arg(full_path).output()?;

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.