On Mon, May 23, 2011 at 8:02 AM, Irfan Sayed <irfan_sayed2...@yahoo.com> wrote: > L:\Console>perl -e qx/"C:\\Program Files\\Microsoft Visual Studio .NET > 2003\\Com > mon7\\IDE\\devenv /rebuild release abc.sln /useenv"/; > > plz suggest on how to correctly format the command so that perl can execute > that command
I'm guessing that the main problem is the Windows shell's awkward syntax. :) I've been trying for years to make sense of it and I still can't. :) Try this: perl -e "print qx'C:\Program^ Files\Microsoft^ Visual^ Studio^ .NET^ 2003\Common7\IDE\devenv /rebuild release abc.sln /useenv'" In order to come up with that I needed to write a C program to be sure arguments were being passed as I expected, then once I was sure how arguments were going to be passed I had to play with perl to figure out the solution. :P <<< #include <stdio.h> int main(int argc, char * argv[]) { int i; for(i=0; i<argc; i++) printf("%d=%s\n", i, argv[i]); return 0; } >>> Compile with MinGW with a command like this: gcc -Wall main.c -o args.exe Then test the arguments you're passing: args Whatever you want here The output should show you which string is in which argument slot. :) cmd.exe is really weird. While ^ is supposed to be the escape character, it seems to only escape certain special characters. As far as I can tell you can't escape white-space. args foo^ bar Outputs: 0=args 1=foo 2=bar That forces you to use double-quotes (single-quotes mean nothing AFAIK) when an argument contains spaces, but then if you also need embedded double-quotes then you need to double them to escape them (instead of using ^" you have to use ""). Then, according to my experiments, the escaped double-quote also terminates the quoted string (which makes zero sense) so you have to start again with a new double-quote if the rest of the argument contains any spaces... The Windows graphical shell might be somewhat refined (in some other people's opinion), but the Windows command shell is certainly not. Once I had that figured out I tried to invoke my args C program using the same rules: perl -e "print qx'"""C:\Documents and Settings\bamccaig\args.exe""" /rebuild release abc.sln /useenv'" Low and behold, that does NOT work. The Windows shell complains that "C:\Documents and Settings\bamccaig\args.exe" (WITH the double-quotes) is not found (as an aside, I originally wrote the args program as a batch file and got the quotes as well). :P Through experimentation, I discovered that you can escape the whitespace using ^ here though (again, completely doesn't make sense based on the cmd.exe interface), which gives me: perl -e "print qx'C:\Documents^ and^ Settings\bamccaig\args.exe /rebuild release abc.sln /useenv'" Which outputs: 0=C:\Documents 1=and 2=Settings\bamccaig\args.exe 3=/rebuild 4=release 5=abc.sln 6=/useenv Which ALSO doesn't make sense! Clearly my C program is being invoked (the output is in the expected format), but the program itself thinks that its path is three arguments, not one. Don't ask me how Microsoft can achieve such epic failure, but they don't seem to have any trouble at all. My advice is to simply not use Microsoft Windows if you need software to work reliably, but I digress... I can't promise that I didn't make any mistakes in writing this E-mail and testing the various ways. It makes such little sense that it's very easy to drive yourself crazy and confuse yourself. :P -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/