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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:49:44+00:00 2026-05-12T20:49:44+00:00

I would like to prepare an old-school argument vector (argv) to use within the

  • 0

I would like to prepare an old-school argument vector (argv) to use within the function

int execve(const char *filename, char
*const argv[],char *const envp[]);

I tried it with the stl::vector class:

std::string arguments = std::string("arg1");    
std::vector<char*> argv; 
char argument[128];
strcpy(argument, arguments.c_str());
argv.push_back(argument); 
argv.push_back('\0'); // finish argv with zero

Finally I pass the vector to execve()

execve(“bashscriptXY”, &argv[0], NULL)

The code compiles but ArgV gets “ignored” by execve(). So it seems to be wrong, what I’m trying. How should I build an argV in a efficient way with c++?

  • 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-12T20:49:44+00:00Added an answer on May 12, 2026 at 8:49 pm

    I think the char[128] is redundant as the string local will have the same lifetime, also, try adding the program as argv[0] like rossoft said in his answer:

    const std::string arguments("arg1");    
    std::vector<const char*> argv;
    
    argv.push_back("bashscriptXY");
    // The string will live as long as a locally allocated char*
    argv.push_back(arguments.c_str()); 
    argv.push_back(NULL); // finish argv with zero
    
    execve(argv[0], &argv[0], NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use a language that I am familiar with - Java,
We would like to prepare a quiz which will improve the vocabulary of the
I would like to put an int into a string . This is what
Function HEX is one of the core functions in sqlite I would like to
I would like to ask about some advices, how to use Symfony2 SonataAdminBundle. I
I would like to prepare session which will be using tables and in another
Needs a better control on releases. I would like to use this plug-in http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html
I would like to trigger a popup box using the function provide by jquery
I would like to prepare a javascript-based system that would deselect the text after
I would like to prepare statements with resultSetHoldability parameter set to ResultSet.CLOSE_CURSORS_AT_COMMIT : PreparedStatement

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.