Jump to content

Command prompt woes (C)


Recommended Posts

I've discovered an odd and frankly rather stupid behaviour of XP's command prompt that's making life difficult. Suppose I have a program named program.exe in a folder, along with the files textfile.txt and image.bmp. If I go to a command line and type "program *.com", the arguments to program.exe are "program" and "*.com". However, if I type "program *.*", the arguments are "program", "image.bmp", "program.exe" and "textfile.txt"! Apparently the command prompt will replace file patterns (* and ?) with any filenames that match them... This makes thins rather difficult as my program needs to know the pattern itself, not the files that match it. :( Can this be disabled or something?

Link to comment
Share on other sites


You're saying that you need to use the * character itself as an argument to your program? Why would you do this? There are plenty of other characters/strings that you can use for arguments.

I think the default behaviour that you're describing is general to most shells. This happens to me when I'm writing in a UNIX environment as well.

If you describe what you're program is doing with the arguments, maybe I can help you a bit better.

Cheers!

Link to comment
Share on other sites

Basically, it's doing exactly what the command prompt is doing for me - finding files that match the pattern. Thing is, it has (or will have, if I can get it working <_<) directory recursion, so I would need to do the matching manually to get the files in deeper directories.

Link to comment
Share on other sites

program *.com should run program with *.com as an argument, although you have no *.com in your folder!

program *.* should run program with *.* as arguments, ie itself, textfile.txt and image.bmp!

How about an explanation of your more precise requirements, your example seems too confusing to give a more precise reply!

Link to comment
Share on other sites

I think my next suggestion would be to try escaping the asterisks with carets i.e program ^*.^*

although using cmd.exe as stated previously should give the correct arguments

input

>program *.* \*.\* ^*.^*

output (echoed)

*.* \*.\* *.*

As you can see the carets were ignored in the output, hence my suggestion, but the original asterisk dot asterisk still worked!

Link to comment
Share on other sites

@IceManND:

I think you're getting he *.* because the program is already starting to read the actual arguments. i.e. it hasn't hit any wildcards yet.

No one here has copied the arguments exactly as HyperHacker had in his original post... unfortunately I don't have a proper compiler on this computer (I'm at work) so I can't test it out.

Link to comment
Share on other sites

Here's the no frills look, returns just what is on the commandline:

#include <stdio.h>

void main( int argc,  char *argv[],  char **envp )
{
   int count;

   printf( "\nCommand-line arguments:\n" );
   for( count = 0; count < argc; count++ )
       printf( "  argv[%d]   %s\n", count, argv[count] );

   return;
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...