HyperHacker Posted May 8, 2005 Share Posted May 8, 2005 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 More sharing options...
Zxian Posted May 10, 2005 Share Posted May 10, 2005 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 More sharing options...
HyperHacker Posted May 10, 2005 Author Share Posted May 10, 2005 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 More sharing options...
Yzöwl Posted May 10, 2005 Share Posted May 10, 2005 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 More sharing options...
HyperHacker Posted May 10, 2005 Author Share Posted May 10, 2005 I need the argument to be literally '*.*', rather than for the shell to supply a list of files. Link to comment Share on other sites More sharing options...
IcemanND Posted May 10, 2005 Share Posted May 10, 2005 That is what I have always gotten in my apps. The actual argument passed.myprog.exe hello *.txt *.* goodbye.*args returned:hello*.txt*.*goodbye.* Link to comment Share on other sites More sharing options...
HyperHacker Posted May 10, 2005 Author Share Posted May 10, 2005 Odd... Are you running it from cmd.exe, command.com, Explorer, or some other shell? Link to comment Share on other sites More sharing options...
Yzöwl Posted May 10, 2005 Share Posted May 10, 2005 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 argumentsinput>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 More sharing options...
HyperHacker Posted May 10, 2005 Author Share Posted May 10, 2005 That might work, but it'd be rather confusing. Maybe I've accidentally enabled some option that does this? A problem in MinGW perhaps? Link to comment Share on other sites More sharing options...
Zxian Posted May 10, 2005 Share Posted May 10, 2005 @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 More sharing options...
IcemanND Posted May 11, 2005 Share Posted May 11, 2005 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now