in reply to VSS automation strange problem

My first thought is that when running the perl script you are not the same user with the same permissions and environment variable that you are when you run the commands by hand. Is the perl script running under some service, Daemon or task scheduler?

Replies are listed 'Best First'.
Re^2: VSS automation strange problem
by cormanaz (Deacon) on Jan 04, 2017 at 00:44 UTC
    I think you are right. I have been running the script via Komodo IDE so I can debug it. I did not configure it as a separate user, but when I run
    #!/usr/bin/perl -w use strict; my $foo = `echo %SSDIR%`; print $foo;
    from it, it shows that the ENV variable is not set, whereas it is from the command line.

    But there is only one user on this (Windows 10) machine. Any idea how to track down what user Komodo is running under?

    "I think computers have complicated lives very bigly. The whole age of, you know, computer has made it where nobody knows exactly what's going on." --D. Trump

      one end user maybe, but many other "users" too. SYSTEM, NETWORK SERVICE, LOCAL SERVICE are but a few others. Maybe this will help, i use it to identify who runs my code from a console

      use Win32; my $user = Win32::LoginName();
      If you can put your process into sleep for a bit and can identify it from this list this may help
      use strict; use warnings; use DBI; use DBD::WMI qw/connect prepare execute fetchrow/; use Win32::OLE qw/in/; # needs DBD::WMI # http://search.cpan.org/~corion/DBD-WMI-0.07/lib/DBD/WMI.pm # corion@cpan.org http://www.perlmonks.org/?node_id=5348 # http://www.perlmonks.org/?node_id=565819 #clues from # http://www.perlmonks.org/?node_id=821593 # https://gist.github.com/aero/1260973/6efbe8684aa54c8aecb73f601e511a5 +3bfb5c6b1 # https://msdn.microsoft.com/en-us/library/aa394388(v=vs.85).aspx # https://msdn.microsoft.com/en-us/library/aa394084(v=vs.85).aspx my $dbh = DBI->connect('dbi:WMI:'); sub do_table{ my @tables=@_; table: for my $table (@tables){ my $sth = $dbh->prepare('SELECT * FROM '.$table); unless ($sth->execute()) { print 'Unable to select from:'.$table." +\n"; next table;} print 'Table:'.$table."\n"; my $rowct=0; while (my( $row ) = $sth->fetchrow) { print ' row:'.$rowct++."\n"; foreach my $object ( in($row->{Properties_}) ) { my $outline=" $object->{Name} = "; if ( ref($object->{Value}) eq "ARRAY") { $outline.="{ "; foreach my $value ( in($object->{Value}) ) {$outline.="$va +lue ";} $outline.="}"; } else { $outline.=($object->{Value} // ""); } print $outline."\n"; } # $object } # thing } # table } # do_table do_table("Win32_Process");

        While win32_process is cute, it doesnt seem to reply with the username like i thought it did. try this instead

        tasklist /v

      Answering your question is one thing, but this may solve your initial problem better. add this to your code before my $result=...

      $ENV{SSDIR}='c:\\some\\path\\to\\some.ini';
      And if you didnt restart your IDE after setting SSDIR outside it by hand that may be what the problem is. And if you set it via a more permanent method you may need to logoff/login again.

        When I run this from Komodo
        #!/usr/bin/perl -w use strict; use Win32; my $user = Win32::LoginName(); print "$user\n\n"; my $tasklist = `tasklist /v`; print $tasklist; chdir('C:\Program Files (x86)\Microsoft Visual SourceSafe'); $ENV{SSDIR} = 'C:\Program Files (x86)\Microsoft Visual SourceSafe'; my $env = `echo %SSDIR%`; print "\n$env\n"; my $result = `SS Dir \"$/\" -Yadmin`; print $result;
        I get the one user (me) on the system, perl.exe has the same user, it echoes the correct SSDIR, then I get the error about the SSDIR variable not being set. When I run echo %USERDOMAIN%\%USERNAME% from the command window I get the same user as the script. Also when I drop the script into the VSS directory and run it from the command line I get the same result, running either in a plain command window or and administrator command window. So I guess it's not a Komodo issue.

        How strange.

        "I think computers have complicated lives very bigly. The whole age of, you know, computer has made it where nobody knows exactly what's going on." --D. Trump