C
C#•2y ago
Torn

Process.Start fails with 'unterminated quoted string' in Linux

I am trying to run 7z to extract some files. The command seems to work if I just run it from the shell directly, but not from code. Maybe it's not the exact same, and I don't realize it. So I'm doing this:
//Unpack dump with 7z
StringBuilder argument = new($"\"{Config.zipPath}\" x \"{dumpPath}\" -so | \"{Config.zipPath}\" x -y -si -ttar");
foreach (string file in new[] { "vn", "vn_titles" /* and other strings */ }) {
argument.Append($" db/{file} db/{file}.header");
}
Process.Start(Config.shell, string.Format(Config.arguments, argument)).WaitForExit();
//Unpack dump with 7z
StringBuilder argument = new($"\"{Config.zipPath}\" x \"{dumpPath}\" -so | \"{Config.zipPath}\" x -y -si -ttar");
foreach (string file in new[] { "vn", "vn_titles" /* and other strings */ }) {
argument.Append($" db/{file} db/{file}.header");
}
Process.Start(Config.shell, string.Format(Config.arguments, argument)).WaitForExit();
The config file is a list of key=value pairs that get loaded into the static Config class. So, it works for Windows:
shell=cmd.exe
zipPath=C:/Program Files/7-Zip-Zstandard/7z.exe
arguments=/C "{0}"
shell=cmd.exe
zipPath=C:/Program Files/7-Zip-Zstandard/7z.exe
arguments=/C "{0}"
but not for Linux:
shell=ash
zipPath=7z
arguments=-c '{0}'
shell=ash
zipPath=7z
arguments=-c '{0}'
Seems the ash command there fails with an error: x: line 0: syntax error: unterminated quoted string
2 Replies
x0rld 👻 🎃
that would be a lot easier to use a lib
Torn
TornOP•2y ago
I'm just trying to run a shell command, this doesn't require a whole library...
Want results from more Discord servers?
Add your server