Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7899467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:42:37+00:00 2026-06-03T08:42:37+00:00

I am writing a small C++ program, which involves starting a .exe process with

  • 0

I am writing a small C++ program, which involves starting a .exe process with many arguments, including sending paths which contain spaces, and hence require double quotes around the path. I have remembered to use the \” escape character.

I have tried lots of different ways of starting this process, and so have ended up at system(), simply to try to make the starting code as minimalist as possible.

I have this code:

string ExpandEnvironmentVariables(string input)
{
    char buffer[512];
    ExpandEnvironmentStringsA(input.c_str(), buffer, sizeof(buffer) / sizeof(*buffer));
    return buffer;
}

which works fine as far as I can tell.

Here is the code I am using to start the process (all the variables are std::string). This one works fine, however, it doesn’t contain all the arguments I want to pass.

system(ExpandEnvironmentVariables("\"" + path + "\" " + arg1 + " -c ").c_str());

This one doesn’t work:

system(ExpandEnvironmentVariables("\"" + path + "\" " + arg1 + " -c \"").c_str());

Notice the addition of the extra double quotes. It is not that the process errors, it is that the process never even starts up.

I am using Process Monitor to detect when the process is starting up, and no process.exe appears in it as soon as I add that extra double quotes into it. However, here is what I want to start the process with (which doesn’t work either)

system(ExpandEnvironmentVariables("\"" + path + "\" " + arg1 + " -c \"" + arg2 + "\"" + arg3 + arg4 + " " + arg5 + arg6 + " " + arg6 + "\\" + arg7).c_str());

I even tried to pair up the double quotes, but this doesn’t work either:

system(ExpandEnvironmentVariables("\"" + path + "\" " + arg1 + " -c \"test\"").c_str());

Finally, I was concerned about length. The addition of the third double quotes is what breaks it. However, before that, the length is 134 characters long. However, I want the actual starting routine to be 346 characters long. This isn’t too long, is it???

I can debug the program, take the formatted string, and paste into Command Prompt, and the process starts perfectly. With those extra quotes, it is formatted perfectly. But I can’t get it to start through C++!

Does anyone know what is going on here? It is driving me absolutely mad! Thank you so much for any help or advice you can offer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:42:38+00:00Added an answer on June 3, 2026 at 8:42 am

    EDIT:

    I will try and suggest you two workarounds:

    1. instead of using " around your arguments, you could replace each space character by \"; to do the replacement correctly, you will have to specify \\" as a replacement string; try it at first without specifying any argument (only for the command name), and see if you can extend it;

    2. write the entire command line to a batch file (it seems you are on Windows), then execute that file.

    Check also this post about Win32 double-quote escaping rules.

    Try this:

    system(ExpandEnvironmentVariables("\"" + path + "\" " + arg1 + " -c \\\"").c_str());
    

    notice the 3 \: you want to pass the backslash to the shell (as if on the command line); if you only escape " once, the shell receives it as such, and interprets it as a string delimiter. what you want is that the shell receives it escaped, hence the double \ in front of \".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small program which needs to create a new file with
I was writing this small script the other day.It is a small program which
I'm currently learning libgmp and to that end I'm writing a small program which
Is there any way of writing pexpect like small program which can launch a
I'm writing a small program which is to be used as a digital distribution
I'm writing a small program which will make a GET request to a server
I'm writing a small program (using Cocoa Touch), which communicates with a webservice. The
I'm writing a small JAVA program which: takes a text as a String takes
I am writing a small program in java which will draw a path on
I am writing a small C++ program which passes a 2-D array (of complex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.