how to call perl script from total commander ?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
xiaomm250
Junior Member
Junior Member
Posts: 18
Joined: 2021-12-03, 09:43 UTC

how to call perl script from total commander ?

Post by *xiaomm250 »

my em command as follow

Code: Select all

[em_DeleteBlankLines]
cmd="%COMMANDER_PATH%\script\DeleteBlankLines.pl"
param="%L"
menu=call perl to delete blank lines
my perl code as follow

Code: Select all

use strict;use warnings;use diagnostics;
my @files=<$ARGV[0]>;#read filenames from %L
foreach my $file (@files)
{
    open(my $FHa,'<',$file);
    my @data=<$FHa>;
    close($FHa);
    open(my $FHb,'>',$file);
    foreach my $line (@data)
    {
        chomp($line);
        if($line=~m/^\s*$/)
        {
            next;
        }
        print $FHb "$line\n";
    }
    close($FHb);
}
but why it doesn't work ?
or who can give me an example which call perl code from total commander ?

I use strawberry perl on Windows 7 64bit
User avatar
nsp
Power Member
Power Member
Posts: 1804
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: how to call perl script from total commander ?

Post by *nsp »

If ".PL" is part of extension in PATHEXT variable and perl interpreter in the path and registered for .pl file this should have worked !

You can add before your script <PATH TP>\perl.exe.

If you want to debug the call, i ususally use for script cmd /k before the script command to see what is not working... and when it is debugged i remove it or change /k to /c.
xiaomm250
Junior Member
Junior Member
Posts: 18
Joined: 2021-12-03, 09:43 UTC

Re: how to call perl script from total commander ?

Post by *xiaomm250 »

nsp wrote: 2021-12-07, 06:44 UTC If ".PL" is part of extension in PATHEXT variable and perl interpreter in the path and registered for .pl file this should have worked !

You can add before your script <PATH TP>\perl.exe.

If you want to debug the call, i ususally use for script cmd /k before the script command to see what is not working... and when it is debugged i remove it or change /k to /c.
".PL" is extension of perl script ,
PATHEXT variable and perl interpreter in the path
I can not understand this sentence very well
my perl.exe PATH "C:\Strawberry\perl\bin\perl.exe"
i ususally use for script cmd /k before the script command to see what is not working.
can you give me an example hyper link in this forum ?
User avatar
nsp
Power Member
Power Member
Posts: 1804
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: how to call perl script from total commander ?

Post by *nsp »

with cmd :

Code: Select all

[em_DeleteBlankLines]
cmd="cmd /k %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param=%L
menu=call perl to delete blank lines
with perl:

Code: Select all

[em_DeleteBlankLines]
cmd="C:\Strawberry\perl\bin\perl.exe %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param="%L"
menu=call perl to delete blank lines
xiaomm250
Junior Member
Junior Member
Posts: 18
Joined: 2021-12-03, 09:43 UTC

Re: how to call perl script from total commander ?

Post by *xiaomm250 »

nsp wrote: 2021-12-07, 12:02 UTC with cmd :

Code: Select all

[em_DeleteBlankLines]
cmd="cmd /k %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param=%L
menu=call perl to delete blank lines
with perl:

Code: Select all

[em_DeleteBlankLines]
cmd="C:\Strawberry\perl\bin\perl.exe %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param="%L"
menu=call perl to delete blank lines
I success call perl script from total commander with your help ,thanks ,
and I make a bug in my perl script because of my unfamiliar with total commander's "%L"
thanks your help !
xiaomm250
Junior Member
Junior Member
Posts: 18
Joined: 2021-12-03, 09:43 UTC

Re: how to call perl script from total commander ?

Post by *xiaomm250 »

nsp wrote: 2021-12-07, 12:02 UTC with cmd :

Code: Select all

[em_DeleteBlankLines]
cmd="cmd /k %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param=%L
menu=call perl to delete blank lines
with perl:

Code: Select all

[em_DeleteBlankLines]
cmd="C:\Strawberry\perl\bin\perl.exe %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param="%L"
menu=call perl to delete blank lines
I debug with "cmd /k" and print script's variables to a txt file, and I success at last!
xiaomm250
Junior Member
Junior Member
Posts: 18
Joined: 2021-12-03, 09:43 UTC

Re: how to call perl script from total commander ?

Post by *xiaomm250 »

nsp wrote: 2021-12-07, 12:02 UTC with cmd :

Code: Select all

[em_DeleteBlankLines]
cmd="cmd /k %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param=%L
menu=call perl to delete blank lines
with perl:

Code: Select all

[em_DeleteBlankLines]
cmd="C:\Strawberry\perl\bin\perl.exe %COMMANDER_PATH%\script\DeleteBlankLines.pl"
param="%L"
menu=call perl to delete blank lines
my perl code

Code: Select all

#perl script called by total commander to delete the blank lines of selected files
#time:20211209_171515
#running version:win7(64bit)+perl5.26.2+Total Commander version 10.00 64bit(2021-06-10)
#---------------------------em commander start---------------------------------------------------------------
#[em_DBLS]
#cmd="cmd /c %COMMANDER_PATH%\script\DeleteBlankLines.pl"
#param="%L"
#menu=call perl script to delete the blank lines of selected files
#if you want to debug the script,please use cmd="cmd /k %COMMANDER_PATH%\script\DeleteBlankLines.pl"
#---------------------------em commander end-----------------------------------------------------------------
use strict;use warnings;use diagnostics;
#Read the content of "%L" file and put it into the array @files, and each line of "%L" is a file name with a full path.
open(my $FH,"<","$ARGV[0]");#$ARGV[0] equals "%L"
my @files=<$FH>;
close($FH);
foreach my $file (@files)#modify the contents of every file
{
    chomp($file);#delete the carriage return(you must remove the \n after the file name, otherwise there will be an error while reading this file!)
    #open the file and read the contents of the file,save it into the array @data.
    open(my $FHa,'<',$file);
    my @data=<$FHa>;
    close($FHa);
    #Open the file again,wipe out the file,then write the modified contents into it.
    open(my $FHb,'>',$file);
    foreach my $line (@data)
    {
        chomp($line);#remove \n at the end of the line
        #If matched the blank line,run next loop!
        if($line=~m/^\s*$/)
        {
            next;
        }
        #Output the nonblank lines to the file
        print $FHb "$line\n";
    }
    close($FHb);
}
Post Reply