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 3397556
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:32:35+00:00 2026-05-18T04:32:35+00:00

On Unix, we can create a new process with fork(); execvp(argv[0], argv); (with a

  • 0

On Unix, we can create a new process with fork(); execvp(argv[0], argv); (with a bit of plumbing working out if we are the parent or child following the fork). In the child process, main(argc, argv) will see the strings exactly as they were passed to execvp.

On Windows, the _spawn() family basically implements fork(); exec(); in one step. So far, so nice. The problem is that by the time we get to main() in the child, our strings are not what they were. Let me give an example.

argv[0] = "foo";
argv[1] = "bar";
argv[2] = "Use spaces and \"quotes\"";
_spawnvp(0, argv[0], argv);

When we get to the child, in main() we will find that, in this example, argv[0] and argv[1] are as expected, but argv[2] has been tokenized on spaces and quotes removed such that

argv[2] == "Use"
argv[3] == "and"
argv[4] == "quotes"

How can I pass an argv structure from the parent to child as is, with it being reinterpreted and altered?

  • 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-05-18T04:32:35+00:00Added an answer on May 18, 2026 at 4:32 am

    According to the Note on MSDN‘s documentation, if you want a string which contains spaces to be passed as a single argument, you need to quote it.

    Spaces embedded in strings may cause unexpected behavior; for example, passing _spawn the string “hi there” will result in the new process getting two arguments, “hi” and “there”. If the intent was to have the new process open a file named “hi there”, the process would fail. You can avoid this by quoting the string: “\”hi there\””.

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

Sidebar

Related Questions

In Unix we can suspend a process execution temporarily and resume it with signals
I can't seem to get the correct Unix epoch time out of this PHP
The UNIX sort command can sort a very large file like this: sort large_file
In some unix flavours you can emulate a slow network connection to, say 4KB/s
Where can I find the source code for Unix environment's cd command? I want
can someone help me with unix command to truncate the contents of the files
Can we use the wmain() function with Unix compilers or it'll work only on/for
My matlab can't recognise the unix('who'); it returns as the 'who' is not an
On Unix, we can specify the ftp username/password in ~/.netrc file and next time
How can I write to files using Python (on Windows) and use the Unix

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.