Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

proper syntax for command

42 views
Skip to first unread message

Irfan Sayed

unread,
May 23, 2011, 8:02:16 AM5/23/11
to Perl Beginners
hi all,

i am using following command to build the solution file using perl

perl says some error : 

following is the error :

Bareword found where operator expected at -e line 1, near "qx/C:\\Program Files\
\Microsoft Visual Studio .NET 2003\\Common7\\IDE\\devenv /rebuild"
syntax error at -e line 1, near "qx/C:\\Program Files\\Microsoft Visual Studio .
NET 2003\\Common7\\IDE\\devenv /rebuild release "
Execution of -e aborted due to compilation errors.

following is the actual command :

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

this is on windows
plz suggest


--irfan

Shawn H Corey

unread,
May 23, 2011, 8:12:00 AM5/23/11
to begi...@perl.org
On 11-05-23 08:02 AM, Irfan Sayed wrote:
> L:\Console>perl -e qx/"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Com
> mon7\\IDE\\devenv /rebuild release abc.sln /useenv"/;

L:\Console>perl -e qx/"C:\\Program Files\\Microsoft Visual Studio .NET

2003\\Common7\\IDE\\devenv \/rebuild release abc.sln /useenv"/;


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

Irfan Sayed

unread,
May 23, 2011, 8:39:19 AM5/23/11
to Shawn H Corey, begi...@perl.org
L:\Console>perl -e qx/"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Com
mon7\\IDE\\devenv \/rebuild release RMSDC.sln \/useenv"/;
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

plz suggest;

________________________________
From: Shawn H Corey <shawn...@ncf.ca>
To: begi...@perl.org
Sent: Monday, May 23, 2011 5:42 PM
Subject: Re: proper syntax for command

-- To unsubscribe, e-mail: beginners-...@perl.org
For additional commands, e-mail: beginne...@perl.org
http://learn.perl.org/

Shawn H Corey

unread,
May 23, 2011, 8:54:13 AM5/23/11
to begi...@perl.org
On 11-05-23 08:39 AM, Irfan Sayed wrote:
> perl -e qx/"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Com
> mon7\\IDE\\devenv \/rebuild release RMSDC.sln \/useenv"/;

perl -e "qx/\"C:\\Program Files\\Microsoft Visual Studio .NET
2003\\Common7\\IDE\\devenv \/rebuild release RMSDC.sln \/useenv\"/;"

Irfan Sayed

unread,
May 23, 2011, 9:17:41 AM5/23/11
to Christian Marquardt, Perl Beginners
L:\Console>perl -e qx-"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Com
mon7\\IDE\\devenv /rebuild release abc.sln /useenv"-;

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

plz suggest

________________________________
From: Christian Marquardt <Christian...@trivadis.com>
To: Irfan Sayed <irfan_s...@yahoo.com>
Sent: Monday, May 23, 2011 5:45 PM
Subject: AW: proper syntax for command


Junk Score: 1 out of 10 (below your Auto Allow threshold)
| Approve sender | Block sender | Block domain

Shawn H Corey

unread,
May 23, 2011, 9:39:40 AM5/23/11
to begi...@perl.org
On 11-05-23 09:17 AM, Irfan Sayed wrote:
> perl -e qx-"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Com
> mon7\\IDE\\devenv /rebuild release abc.sln /useenv"-;

Put the double quotes outside of the entire Perl command:

perl -e "qx/C:\\Program Files\\Microsoft Visual Studio .NET
2003\\Common7\\IDE\\devenv \/rebuild release RMSDC.sln \/useenv/;"

Try copy & pasting the above.

Irfan Sayed

unread,
May 23, 2011, 10:04:50 AM5/23/11
to Shawn H Corey, begi...@perl.org, Christian...@trivadis.com
hi shawn,
same error :

C:\workspace\CCS_Enzo_11\scm>perl -e "qx/\"C:\\Program Files\\Microsoft Visual S
tudio .NET 2003\\Common7\\IDE\\devenv \/rebuild release RMSDC.sln \/useenv\"/;"


'C:\Program' is not recognized as an internal or external command,
operable program or batch file.


hi christian,

i want to execute follwoing command using perl

"C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv" /rebuild release abc.sln /useenv

plz suggest


________________________________
From: Shawn H Corey <shawn...@ncf.ca>
To: begi...@perl.org

Sent: Monday, May 23, 2011 7:09 PM
Subject: Re: AW: proper syntax for command

-- To unsubscribe, e-mail: beginners-...@perl.org

Rob Dixon

unread,
May 23, 2011, 10:25:01 AM5/23/11
to Perl Beginners, Irfan Sayed

Hi Irfan.

Try this

perl -e "qx{\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\devenv\" /rebuild release RMSDC.sln /useenv}"

(Although I don't understand why you need to execute the command through
Perl instead of directly.)

Rob

Irfan Sayed

unread,
May 23, 2011, 10:32:22 AM5/23/11
to Rob Dixon, Perl Beginners
Hi Rob,
thanks.

my entire build script is in perl and i want this command to be executed in perl

so please let me know what is the best way to execute this command in perl

--irfan

________________________________
From: Rob Dixon <rob....@gmx.com>
To: Perl Beginners <begi...@perl.org>
Cc: Irfan Sayed <irfan_s...@yahoo.com>
Sent: Monday, May 23, 2011 7:55 PM


Subject: Re: proper syntax for command

On 23/05/2011 13:02, Irfan Sayed wrote:

Hi Irfan.

Try this

Rob

--

Rob Dixon

unread,
May 23, 2011, 10:44:33 AM5/23/11
to Perl Beginners, Irfan Sayed
On 23/05/2011 15:32, Irfan Sayed wrote:
> From: Rob Dixon<rob....@gmx.com>

> Sent: Monday, May 23, 2011 7:55 PM
>
>> On 23/05/2011 13:02, Irfan Sayed wrote:
>>>
>>> i am using following command to build the solution file using perl
>>>
>>> perl says some error :
>>>
>>> following is the error :
>>>
>>> Bareword found where operator expected at -e line 1, near "qx/C:\\Program Files\
>>> \Microsoft Visual Studio .NET 2003\\Common7\\IDE\\devenv /rebuild"
>>> syntax error at -e line 1, near "qx/C:\\Program Files\\Microsoft Visual Studio .
>>> NET 2003\\Common7\\IDE\\devenv /rebuild release "
>>> Execution of -e aborted due to compilation errors.
>>>
>>> following is the actual command :
>>>
>>> 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
>>>
>>> this is on windows
>>> plz suggest
>>
>> Hi Irfan.
>>
>> Try this
>>
>> perl -e "qx{\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\devenv\" /rebuild release RMSDC.sln /useenv}"
>>
>> (Although I don't understand why you need to execute the command through
>> Perl instead of directly.)
>>
>
> my entire build script is in perl and i want this command to be executed in perl
>
> so please let me know what is the best way to execute this command in perl

I would write it as below.

HTH,

Rob


use strict;
use warnings;

use autodie 'system';

my $devenv = 'C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv';

my $status = system($devenv, '/rebuild release abc.sln', '/useenv');


Irfan Sayed

unread,
May 23, 2011, 1:01:00 PM5/23/11
to Rob Dixon, Perl Beginners
i tried this code, but in actual it is not executing the solution file.
instead, it is opening the solution file and saying /rebuild release file not found

plz suggest . i am really stuck

________________________________
From: Rob Dixon <rob....@gmx.com>
To: Perl Beginners <begi...@perl.org>
Cc: Irfan Sayed <irfan_s...@yahoo.com>

Sent: Monday, May 23, 2011 8:16 PM


Subject: Re: proper syntax for command


You chose to allow Rob Dixon (rob....@gmx.com) even though this message failed authentication
Click to disallow

Jim Gibson

unread,
May 23, 2011, 10:42:22 PM5/23/11
to Perl Beginners
At 10:01 AM -0700 5/23/11, Irfan Sayed wrote:
>i tried this code, but in actual it is not executing the solution file.
>instead, it is opening the solution file and saying /rebuild release
>file not found
>
>plz suggest . i am really stuck

Please show us the code you tried and the exact error message. Cut
and paste the code and output, do not retype.

I believe you are trying to run an external executable from a Perl
program. Please also show us the command-line version that does what
you want. You should be able to package that exact line in a call to
system, but try it from the same directory where the Perl program
resides.

Irfan Sayed

unread,
May 24, 2011, 2:17:52 AM5/24/11
to Jim Gibson, Perl Beginners
here is the actual code:

use strict;
use warnings;
use Cwd;
chdir "L:\\Console";
my $dir = getcwd();
print "current dir is : $dir\n";
my $res = system("dir");
$res=system("devenv","/rebuild","release","abc.sln","/useenv");
print "$res\n";


now, the issue is , at last the value of $res is 256 instead of the real output of command.
just to give details, devenv is the compiler which compiles the solution file. i need to compile the solution file abc.sln and print the entire output of command on the console


pls suggest
--irf


________________________________
From: Jim Gibson <jimsg...@gmail.com>
To: Perl Beginners <begi...@perl.org>
Sent: Tuesday, May 24, 2011 9:19 AM


Subject: Re: proper syntax for command


You chose to allow Jim Gibson (jimsg...@gmail.com) even though this message failed authentication
Click to disallow

Kenneth Wolcott

unread,
May 24, 2011, 2:28:26 AM5/24/11
to Perl Beginners
On Mon, May 23, 2011 at 23:17, Irfan Sayed <irfan_s...@yahoo.com> wrote:
> here is the actual code:
>
> use strict;
> use warnings;
> use Cwd;
> chdir "L:\\Console";
> my $dir = getcwd();
> print "current dir is : $dir\n";
> my $res = system("dir");
> $res=system("devenv","/rebuild","release","abc.sln","/useenv");
> print "$res\n";
>
>
> now, the issue is , at last the value of $res is 256 instead of the real output of command.
> just to give details, devenv is the compiler which compiles the solution file. i need to compile the solution file abc.sln and print the entire output of command on the console
>
>
> pls suggest
> --irf

I didn't do "Replay-all" :-()

n place of "system", try using back-quiotes (known as grave with an
accent from the French) to "execute the statement and preserve the
output". Or use the "qx" operator. The results of the command should
be assigned to the variable. Do you have a verbose option for your
compiler call?

Hope this helps,
Ken Wolcott

Jim Gibson

unread,
May 24, 2011, 2:34:41 AM5/24/11
to Perl Beginners
At 11:17 PM -0700 5/23/11, Irfan Sayed wrote:
>here is the actual code:
>
>use strict;
>use warnings;
>use Cwd;
>chdir "L:\\Console";
>my $dir = getcwd();
>print "current dir is : $dir\n";
>my $res = system("dir");
>$res=system("devenv","/rebuild","release","abc.sln","/useenv");
>print "$res\n";
>
>now, the issue is , at last the value of $res is 256 instead of the
>real output of command.
>just to give details, devenv is the compiler which compiles the
>solution file. i need to compile the solution file abc.sln and print
>the entire output of command on the console

The system function returns an error or success value. The standard
output of the command executed by system should end up on your
terminal.

If you want to capture the output of the command, use backticks or
the qx operator:

my @output = qx( devenv /rebuild release abc.sln /useenv);

See 'perldoc -q system' "Why can't I get the output of a command with
system()?"
and 'perldoc -f system'.

Brandon McCaig

unread,
May 24, 2011, 5:06:15 PM5/24/11
to Irfan Sayed, Perl Beginners
On Tue, May 24, 2011 at 5:03 PM, Brandon McCaig <bamc...@gmail.com> wrote:
> perl -e "print qx'C:\Program^ Files\Microsoft^ Visual^ Studio^ .NET^
> 2003\Common7\IDE\devenv /rebuild release abc.sln /useenv'"

This should of course be one line (with a space between the ^ and the 2).

> perl -e "print qx'"""C:\Documents and Settings\bamccaig\args.exe"""
> /rebuild release abc.sln /useenv'"

This should of course be one line (with a space between the " and /).

> perl -e "print qx'C:\Documents^ and^ Settings\bamccaig\args.exe
> /rebuild release abc.sln /useenv'"

This should of course be one line (with a space between the e and /).

I should possibly note too that I did these tests in a Windows XP VM
so YMMV. Maybe the behavior has improved in Vista or Seven, but I
doubt it. ;D

--
Brandon McCaig <http://www.bamccaig.com/> <bamc...@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamc...@castopulence.org>

Brandon McCaig

unread,
May 24, 2011, 5:03:43 PM5/24/11
to Irfan Sayed, Perl Beginners
On Mon, May 23, 2011 at 8:02 AM, Irfan Sayed <irfan_s...@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

0 new messages