can't run "devenv" in Perl

S

Slickuser

Hi,

How can I fixed the error below so that I can run "devenv" in Perl?
Thanks.

setVSEnv();
system("devenv /Build Debug \"ProjectABC.sln\" /out \"C:/log_out.txt
\");

Error:
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
'devenv' is not recognized as an internal or external command,
operable program or batch file.

sub setVSEnv
{
## VS 2005
my $VS_Path = $ENV{'VS80COMNTOOLS'};
if (defined($VS_Path))
{
system("call \"%vs80comntools%vsvars32.bat\" ");
}
else
{
## VS 2003
$VS_Path = $ENV{'VS71COMNTOOLS'};
if (!defined($VS_Path))
{
print STDERR "Visual Studio doesn't exist.\n";
exit(0);
}
system("call \"%vs71comntools%vsvars32.bat\" ");
}
}
 
J

Jürgen Exner

Slickuser said:
How can I fixed the error below so that I can run "devenv" in Perl?

setVSEnv();
system("devenv /Build Debug \"ProjectABC.sln\" /out \"C:/log_out.txt
\");

Error:
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
'devenv' is not recognized as an internal or external command,
operable program or batch file.

Two possibilities:
- add the directory that contains devenv.<whatever> to your path
- calll devenv.<whatever> using the absolute path rather then the
relative local path

jue
 
S

sln

Hi,

How can I fixed the error below so that I can run "devenv" in Perl?
Thanks.

setVSEnv();
system("devenv /Build Debug \"ProjectABC.sln\" /out \"C:/log_out.txt
\");

Error:
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
'devenv' is not recognized as an internal or external command,
operable program or batch file.

sub setVSEnv
{
## VS 2005
my $VS_Path = $ENV{'VS80COMNTOOLS'};
if (defined($VS_Path))
{
system("call \"%vs80comntools%vsvars32.bat\" ");
}
else
{
## VS 2003
$VS_Path = $ENV{'VS71COMNTOOLS'};
if (!defined($VS_Path))
{
print STDERR "Visual Studio doesn't exist.\n";
exit(0);
}
system("call \"%vs71comntools%vsvars32.bat\" ");
}
}

I think the 'system()' function forkes a new process. As soon as the process goes
away the @sets go away before you call the devenv. Try using exec(), it should work.

If that doesen't work you could dynamically create a batch file then run it with system().
Something like this:

mybuild.bat
------------------
call "C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
devenv.exe "C:\(full path)\ProjectABC.sln" /rebuild "Release" /out log_out.txt

sln

=====================================
use strict;
use warnings;

open my $fh, '>', 'mybuild.bat' or die "can't create mybuild.bat...";
print $fh makeBatchFile('"(full path)\ProjectABC.sln" /rebuild "Release" /out log_out.txt');
close $fh;

system (" mybuild.bat ");

sub makeBatchFile
{
my $solution = shift;
my $str = '';

## VS 2005
my $VS_Path = $ENV{'VS80COMNTOOLS'};
## VS 2003
$VS_Path = $ENV{'VS71COMNTOOLS'} unless (defined $VS_Path);

if (!defined($VS_Path)) {
print STDERR "Visual Studio doesn't exist.\n";
exit(0);
}
return "\@echo off\n\@cls\ncall \"".$VS_Path."vsvars32.bat\"\ndevenv $solution\n";
}

__END__

output:

Setting environment for using Microsoft Visual Studio 2005 x86 tools.

Microsoft (R) Visual Studio Version 8.0.50727.762.
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.

The following files were specified on the command line:

(full path)\ProjectABC.sln

These files could not be found and will not be loaded.

C:\temp>
 
S

Slickuser

I think the 'system()' function forkes a new process. As soon as the process goes
away the @sets go away before you call the devenv. Try using exec(), it should work.

It doesn't work so I am going with the calling absolute full path to
devenv.exe directly.
 
J

Jürgen Exner

Slickuser said:
It doesn't work so I am going with the calling absolute full path to
devenv.exe directly.

Well, I don't know what problem the previous poster tried to solve by
using exec() instead of system() (his article doesn't show up).
But whatever it is, I cannot fathom why replacing the Perl process with
another process would be an improvement over running the other process
while the Perl process is waiting.

jue
 
S

sln

Yeah, thats too bad. Just blast some static text from a batch file
"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe" "(full path)\ProjectABC.sln" /rebuild "Release" /out log_out.txt

Here is the script again incase it didn't come through the first time. It works fine

=====================
use strict;
use warnings;

open my $fh, '>', 'mybuild.bat' or die "can't create mybuild.bat...";
print $fh makeBatchString('"(full path)\ProjectABC.sln" /rebuild "Release" /out log_out.txt');
close $fh;

system (" mybuild.bat ");

sub makeBatchString
{
my $solution = shift;
my $VS_Path = $ENV{'VS80COMNTOOLS'};
$VS_Path = $ENV{'VS71COMNTOOLS'} unless (defined $VS_Path);
if (!defined($VS_Path)) {
print STDERR "Visual Studio doesn't exist.\n";
exit(0);
}
return "\@echo off\n\@cls\ncall \"".$VS_Path."vsvars32.bat\"\ndevenv $solution\n";
}

__END__

output:

Setting environment for using Microsoft Visual Studio 2005 x86 tools.
Microsoft (R) Visual Studio Version 8.0.50727.762.
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.

.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top