can't run "devenv" in Perl

Discussion in 'Perl Misc' started by Slickuser, Oct 13, 2008.

  1. Slickuser

    Slickuser Guest

    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\" ");
    }
    }
    Slickuser, Oct 13, 2008
    #1
    1. Advertising

  2. Slickuser <> wrote:
    >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
    Jürgen Exner, Oct 13, 2008
    #2
    1. Advertising

  3. Slickuser

    Guest

    On Mon, 13 Oct 2008 10:29:01 -0700 (PDT), Slickuser <> wrote:

    >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>
    , Oct 13, 2008
    #3
  4. Slickuser

    Slickuser Guest


    >
    > 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.
    Slickuser, Oct 14, 2008
    #4
  5. Slickuser <> wrote:
    >> 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.


    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
    Jürgen Exner, Oct 14, 2008
    #5
  6. Slickuser

    Guest

    On Mon, 13 Oct 2008 17:38:57 -0700, Jürgen Exner <> wrote:

    >Slickuser <> wrote:
    >>> 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.

    >


    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.

    .....
    , Oct 14, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Selden McCabe

    Devenv.exe Hangs on Compile... Why?

    Selden McCabe, Aug 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,382
    Selden McCabe
    Oct 1, 2004
  2. duncan
    Replies:
    2
    Views:
    6,070
  3. Replies:
    0
    Views:
    863
  4. Replies:
    2
    Views:
    153
    Tad McClellan
    Mar 26, 2005
  5. Replies:
    1
    Views:
    91
    J. Gleixner
    Apr 25, 2006
Loading...

Share This Page