Windows Komodo Perl back tick to run cmd.exe commands

Hello,
Developing in Perl under Windows Komodo, how do I use the Perl back tick `` to run a Windows command shell command? My results always generate a -1 uncaught exception.

However also In Windows 11 command shell, I can use the ActiveState Perl command line debugger to invoke back tick.
Thanks again,
Wil Blake

I don’t think I understand the request. Could you provide a code sample and steps to reproduce the issue?

My mistake for the inadequate explanation. I would like to use `` back tick to obtain the result from a shell command.
This brief Perl code dies with the back tick return code indicating a -1 exception depicted in the enclosed screenshot debug output. Does Windows call for a special module to support shell commands?

use strict;
use diagnostics;
use say;

my $result = `dir` ;
 
if ($? != 0) {
    die "shell returned $?";
}

From the Komodo Tool Perl Interactive Shell, back tick returns -1 as well.

$result=`dir`;
print $result;
print $?

-1
BackquoteKomodoPerlShell

On the other hand If I invoke back tick from the State Project Perl Debugger, it works. This State Project cmd.exe shell is also where I launch komodo via
ko

Thanks for clarifying @wblake.

Using your code sample in both a Perl file and running it through the debugger and running the code manually (copy + pasting into the shell) in a Komodo instantiated Perl Interactive Shell, I can successfully execute and get results.

Is there any way you can get Perl to tell you more than just the error code returned? As far as I can tell, it looks like the dir command fails and Perl is running fine.

My off the top of my head guess would reach back to when we found that your PATH variable was misconfigured in the Komodo preferences. I bet, if you can get Perl to give you more details on the error occurring when dir runs, the error you’ll get back is that dir isn’t a known command.

So action items:

  1. try to get back more than just -1 from Perl regarding the running of dir
  2. Check your project and global (edit menu > Preferences) prefs to make sure your PATH isn’t being edited in any way.
  • Carey

Thanks yet again, careyh.

Sadly the path issue has repeated. I will again clean up the ActiveState Projects via
state clean cache and then modify the PATH variables.

Should the current ActiveState Komodo Project Preferences have a different PATH than the Global Komodo Editor Preferences?

How can I determine which (if any) cached path in *AppData\Local\ActiveState\cache* is right for Komodo Global Preferences or Komodo Project Preferences ?

Similarly should the Perl interpreter in both Global and Project Preferences have the value “Find in Path” or point to a Perl executable in one of the cached paths in
*AppData\Local\ActiveState\cache*

Regards,
Wil Blake

This shouldn’t be necessary. Where and why are you planning on editing your PATH? It sounds like you need to avoid doing that at all cost.

I don’t dictate your use case. If I were you, I would avoid this if I could. I can’t think of a reason why I would edit the PATH env var in Komodo instead of setting specific language preferences.

You’d have to ask in the state tool support forums. I’m often confused by the decisions made around how the state tool manages it’s resources.

Again, this is up to your use case. They should be set to whatever you need them to be set to. In this particular case, if I recall correctly, Komodo can’t detect Perl installed by the state tool because it’s a *.bat file for some reason. So I think for your use case it can’t be Find on Path.

Summary, if you don’t HAVE to edit the PATH I’d avoid doing it at all.

1 Like

Thanks again, careyh.
Can you please reveal from your Komodo testing what Perl build/version succeeds with back tick ?
I will try and find more debugging information on the -1 status failure. In other environments, “Dos shell” exec commands need a full path names to the executable command and filename arguments , along with quoted strings for any command option switches- perhaps that’s another thing to try…

Looks like I’m using 5.34
This is perl 5, version 34, subversion 0 (v5.34.0) built for MSWin32-x64-multi-thread

So is there no way to get more information from the backtick run command? Do you have access to the stdout or stderr of the subshell, sub process, that executes the dir command in the backticks?

Is there another way you can run this so that you do have access to stderr?

From the the ActiveState Project cmd.exe command line (that also launches ko), the Perl 5.34 based proof of concept backtick application worked. I can try to run the Perl backtick proof of concept from the Komodo Tool menu Run Command and observe the output in the Komodo IDE bottom pane.

Looks like the path to CMD.exe remains unavailable as you stated from the beginning. Can Komdo IDE open an interactive CMD.exe shell window?

What are you trying to do? There are ways to do this but not super easily, not with a button click as far as I recall.

Please elaborate ^^ How are you determining this?

If you’re setting the PATH variable anywhere in your prefs then I’d start by removing that change and not add it back.