C Program argv does not contain double quotes


I want to write c program which calls another exe. This wrapper c program does nothing but set some environment variable before I call my original exec.
For example, say I have an exe called test.exe and I wrote testwrapper.exe
I want to call it as testwrapper.exe < parameter >, and internally it should call test.exe < parameter >

My problem is that when I call test.exe as test.exe "c:\program files\input",
C escapes with " passes as parameter

What is causing this problem, and what can I do to fix it?

Best Solution

The quotes are supposed to allow for arguments with spaces. For example:

test.exe "this is an argument with spaces"

In order to put quotes in the argument, escape them:

test.exe "\"c:\program files\input\""

If you were calling this from within a C program, you'd have to double-escape the quotes. For example:

system("test.exe \"\\\"c:\\program files\\input\\\"\"");

It would be helpful, though, to see your line of code that runs test.exe.

Related Question