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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:06:07+00:00 2026-06-07T14:06:07+00:00

what does it take to make my program accept command-line arguments with spaces? Yet-another

  • 0

what does it take to make my program accept command-line arguments with spaces?

Yet-another EDIT: I have just recognized that the program is started from a shell-script that sets up the environment for the execution of the program. As there are some external libraries, LD_LIBRARY_PATH is set to the current working directory:

#!/bin/sh

ARCH=`uname -m`
export LD_LIBRARY_PATH=".:lib/magic/linux-${ARCH}"

./data_sniffer.bin $*

exit $?

The issue is definitely related to $*. Is there any solution to correctly forward the command-line parameters?

Here is a code-snippet from main():

if (stat(argv[1], &lStat) != 0)
{   
    fprintf(stderr, "Cannot stat(2) given file: %s. \n", argv[1]);
    return EXIT_FAILURE;
}   

I am starting my program with the following parameters:

./data_sniffer /mnt/pod/movies/some\ test\ movie\ file.avi

The resulting error message looks like this:
Cannot stat(2) given file: /mnt/pod/movies/some.

Anyone an idea what’s wrong here? I think that I am not the first one with this problem (though, I could not find a related question here).

  • 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-07T14:06:09+00:00Added an answer on June 7, 2026 at 2:06 pm

    Replace the use of ./data_sniffer.bin $* with ./data_sniffer.bin "$@" in your wrapper script and the arguments should be forwarded in a correct manner.

    More regarding the difference between $*, $@ and "$@" can be found here.


    the author of this question changed it completely and came forward with more information regarding the matter, I will let everything already written stand but please remember that this was written before his/her last edit..


    Regarding argv..

    It doesn’t require much from you as a developer, I’m tempted (and it’s much more truthful) to say that it requires nothing of you.

    Arguments passed to the application is handled by the shell executing the binary, doing this below should definitely work the way you want it to (even though I find it odd that you are claiming that the current shell doesn’t handle '\ ' correctely):

    ./data_sniffer '/mnt/pod/movies/some test movie file.avi'
    ./data_sniffer /mnt/pod/movies/some\ test\ movie\ file.avi
    
    # there should be no difference between the two
    

    My recommendation(s)

    • Have you tried doing printf ("argv[1]: %s\n", argv[1]); in the beginning of main to validate the contents of it?

    • Are you sure that you are invoking the correct binary with the correct command-line arguments?

    Sadly the only reasonable thing to write is that you are doing something wrong. We are however unable to answer what without further information regarding the issue.

    I find it very hard to believe that there is a bug in your shell, even though that is of course possible – I doubt it.


    Parsing the command-line into argv isn’t something that you as a developer should worry about, there are no enforced functionality that you have to implement for the binary itself to handle spaces in it’s argument(s).

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

Sidebar

Related Questions

(1) At the bottom line: what does it all have to take to in
I try to make a simple program that does the following: I have two
I'm trying to write a program that will take an HTML file and make
I have a button in my program that, when pressed, is supposed to take
I am writing a command-line plugin-based program where the plugins will provide additional functionality
I've noticed some weird behavior with NSBundle when using it in a command-line program.
Change the environment variable `PATH' in Makefile does NOT take effect with make in
What does it take to add a menu option to the iPhone's Photos/Camera app
Why does it take forever for ASP.NET to process a request the first time
I need to use a function on a vector that does not take a

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.