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

  • Home
  • SEARCH
  • 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 8563007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:51:36+00:00 2026-06-11T16:51:36+00:00

I have written child command execution code for Win32 using CreateProcess: CreateProcessW(NULL, // app

  • 0

I have written child command execution code for Win32 using CreateProcess:

  CreateProcessW(NULL, // app
                 &commandW[0], // command line
                 NULL, // process security attributes
                 NULL, // primary thread security attributes
                 TRUE, // handles are inherited
                 0, // creation flags
                 NULL, // use parent's environment
                 NULL, // use parent's current directory
                 &startup_info, // STARTUPINFOW pointer
                 &process_info); // receives PROCESS_INFORMATION

This uses a “trick” and puts the whole command in the second argument, which normally only contains the arguments being passed to the program. I want to do the same thing for POSIX, but the same “trick” doesn’t work with the execlp function (and I bet all the others as well). Is there any way to still use a single std::string command and to start a process? Splitting the command into an executable filename and the arguments would be possible, but a lot of work I’d like to avoid if possible.

  • 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-11T16:51:38+00:00Added an answer on June 11, 2026 at 4:51 pm

    You could invoke a shell, and pass the big string to the shell, and let the shell deal with it. Try it yourself:

    sh -c "echo 'hello world'"
    

    (i.e. pass two arguments, “-c” and the big string containing the command and arguments)

    Even better: Make the first command exec, which will make your new process “replace” the shell that it spawned, then no one will even know that it was launched using a shell.

    As pointed out in the comments by @ecatmur, this is the exact functionality of the system call.

    But you are opening yourself up to potential (serious) problems: You now have to deal with quoting and escaping of characters. The shell can (and will) interpret any special characters unless they are escaped, and any arguments that have spaces must be properly quoted.

    There is a reason that Unix-like operating systems handle arguments the way that they do.

    My opinion is that the Windows method is fundamentally flawed. It’s a serious design oversight that prevents you from passing complex strings as command line arguments to other programs.

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

Sidebar

Related Questions

I have written a function that attempts to read a child process's command line
I have written a piece of code : public class Child{ int y ;
I have written the following code using node.js and riak-js . I have a
I have written an MDI app with many child forms, each different. Let's say
I have written some CSS which targets elements using the parent > child selector.
I have written a base class from which I wish to derive several child
I have a parent and a child process written in C language. Somewhere in
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I need to access child window elements from parent window. I have written the

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.