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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:53:07+00:00 2026-05-12T07:53:07+00:00

I’m feel like I’m missing something pretty obvious here, but I can’t seem to

  • 0

I’m feel like I’m missing something pretty obvious here, but I can’t seem to figure out what’s going on. I have a perl script that I’m calling from C code. The script + arguments is something like this:

my_script "/some/file/path" "arg" "arg with spaces" "arg" "/some/other/file"

When I run it in Windows, Perl correctly identifies it as 5 arguments, whereas when I ran it on the SunOS Unix machine, it identified 8, splitting the arg with spaces into separate args.

Not sure if it makes any difference, but in Windows I’m running it like:

perl my_script <args>

While in Unix I’m just running it as an executable like show above.

Any idea why Unix is not managing that argument properly?

Edit:

Here’s the code for calling the perl script:

 char cmd[1000];
 char *script = "my_script";
 char *argument = "\"arg1\" \"arg2\" \"arg3 with spaces\" \"arg4\" \"arg5\"";
 sprintf( cmd, "%s %s >1 /dev/null 2>&1", script, arguments);
 system( cmd );

That’s not exactly it, as I build the argument string a little more dynamically, but that’s the gist.

Also, here’s my code for reading the arguments in:

($arg1, $arg2, $arg3, $arg4, $arg5) = @ARGV;

I know it’s ridiculously naive, but this script will only be run from the C application, so nothing more complex should be required.

  • 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-12T07:53:07+00:00Added an answer on May 12, 2026 at 7:53 am

    Presumably

    system("my_script \"/some/file/path\" \"arg\" \"arg with spaces\" \"arg\" \"/some/other/file\");
    

    causes everything to go through bash (because of the need to interpret the shebang line, eating up the quotes you pass). Again, presumably, the problem could be avoided by invoking perl directly rather than relying on the shell to find it (although this might be a problem if the perl on the path is different than the one provided on the shebang line).

    Update:

    Given your:

    char *argument = "\"arg1\" \"arg2\" \"arg3 with spaces\" \"arg4\" \"arg5\"";
    

    you might want to try:

    char *argument = "\\\"arg1\\\" \\\"arg2\\\" \\\"arg3 with spaces\\\" \\\"arg4\\\" \\\"arg5\\\"";
    

    Another update:

    Thank you for accepting my answer, however, my whole theory might be wrong.

    I tried the double-backwhacked version of argument above in GNU bash, version 4.0.28(2)-release (i686-pc-linux-gnu) and it ended up passing

    [sinan@kas src]$ ./t
    '"arg1"'
    '"arg2"'
    '"arg3'
    'with'
    'spaces"'
    '"arg4"'
    '"arg5"'
    

    whereas the original argument worked like a charm. I am a little puzzled by this. Maybe the shell on the SUN isn’t bash or maybe there is something else going on.

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

Sidebar

Ask A Question

Stats

  • Questions 244k
  • Answers 244k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Asp.Net framework uses "HTMLTextWriter" class to generate the HTMl markup… May 13, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer I'm a bit confused – are you using PHP sessions,… May 13, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer Another possibility is fetching the file names with glob(). Its… May 13, 2026 at 7:57 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.