I'm attempting to create a simple C program to dump the raw command line to debug the output of programs that call other programs. Here is what I have so far:
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
for (i = 0; i < argc; i++)
fprintf (stderr, "%s ", argv[i]);
fputs ("\n", stderr);
return (0);
}
There are several problems with this method. First of all, I have to insert a space manually after every argument. Secondly, the qouting on the original command like is lost, so with input like this:
./argvdump "'something'" """'"'""""other things""""'"'"""
I get output like this:
./argvdump something other things
which isn't very useful for debugging since I can't see what was actually on the command line.
Does anyone know how to get the actual raw command line?
The OS (or more specifically the shell) is the piece doing things like removing whitespace and quotes. There is no way to reconstruct the whole command line including all of those artifacts.
You could assume that if an argv member contains a space then originally it had quotes around it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With