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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:13:56+00:00 2026-05-28T07:13:56+00:00

I cannot get execv() to work in my C program. I suspect the problem

  • 0

I cannot get execv() to work in my C program. I suspect the problem is in this segment, something having to do with char* args[10]. Here is the segment:

  void mySystem(char *str, int *num_f, int *sig_k)  {
   int pid, stat;

   if ( fork() == 0)  {
    char * args[10];
    args[0] = str;
    args[1] = NULL;

    execv(str, &args);
    exit(20);

This gives a warning of:

systest.c:17: warning: passing argument 2 of âexecvâ from incompatible pointer type

I have been working for hours, and tried seemingly everything. What is going on? Here is all the code, just for reference incase I am making an unrelated error:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>


void mySystem(char *str, int *num_f, int *sig_k)  {
   int pid, stat;

   if ( fork() == 0)  {

        char * args[10];
        args[0] = str;
        args[1] = NULL;

        execv(str, &args);
        exit(20);               
   }

   pid = wait(&stat);
   if (WEXITSTATUS(stat) != 0)  {
        printf("command %s failed (exit code %d)\n", str, WEXITSTATUS(stat));
   } else {
        printf("command %s success (exit code 0)\n", str);
        num_f += 1;
        printf("wat %d\n", num_f);
   }


}       //mySystem



int main() {

   char buf[100];
   char cmd[100];       
   int num_fails = 0, sig_kills = 0;

   while(fgets(buf, 100, stdin)){
        sscanf(buf, "%s", cmd);
        if (strcmp(cmd, "quit") == 0) {
                printf("ran with %s\n", cmd);
                printf("num success = %d\n",num_fails);
                exit(0);        //returns 0 if equal, 1 if not
         }

printf("in main %s\n", cmd); 
        mySystem(cmd, &num_fails, &sig_kills);
   } 


return 0;

}

When ran, all commands just fail. Any help is greatly appreciated.

  • 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-28T07:13:56+00:00Added an answer on May 28, 2026 at 7:13 am

    What execv wants is a char *[], i.e. an array of pointer, which is what you define with args.

    If you add the & to args you get the type char *(*[]), that is a pointer to an array of pointers. Skip the & in the execv call and it will all work.

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

Sidebar

Related Questions

I cannot get a two-way bind in WPF to work. I have a string
I cannot get the internet explorer web developer tool bar to work with a
I cannot get Bindable LINQ to work with VB.NET for the life of me.
I cannot get the jQuery slideDown function to work on <table> elements. They just
I cannot get shell_exec ( 'svn up /var/www/mydirectory' ) to work. For some reason
Hey guys and girls, i'm stumped. Trying to get array_search to work with this
This problem is probably very easy to solve but somehow I cannot find a
I cannot get the Full-Text search to work on PDF files I am loading
I have google the heck out of this an I cannot get an answer
I cannot get std::tr1::shared_ptr for my WinMobile project since the STL for WinCE is

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.