Strange problem with Perl scripts: How does TP launch tools?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
AntiEntropy
Posts: 11
Joined: Sat Sep 20, 2003 12:28 am

Strange problem with Perl scripts: How does TP launch tools?

Post by AntiEntropy »

I have several Perl scripts that I use as tools in TP. They work fine like this:

Code: Select all

Command: c:\perl\bin\perl.exe
Parameters: c:\path\to\script.pl -switch1 -switch2 $File
My problem is that "\path\to\script" changes a lot, so I'm in Configure -> Preferences changing things all the time. I'm also trying to simplify the setup for less sophisticated users (programmers) who I support. What I'd really like to do is use environment variables like this:

Code: Select all

Command: c:\perl\bin\perl.exe
Parameters: %SCRIPT_PATH%\script.pl -switch1 -switch2 $File
Then I could just changed SCRIPT_PATH, but environment variables aren't expanded, so I tried this:

Code: Select all

Command: script.pl
Parameters: -switch1 -switch2 $File
That way at least I could put "\path\to\scripts\" in PATH and just change that instead of a dozen tools. But when I do that, I get this error:

"Unrecognized switch: -switch1 (-h will show valid options)."

That's perl.exe talking. It's as if I typed in "perl -switch1". My FTYPE for Perl scripts looks like this:

ftype Perl=c:\perl\bin\perl.exe "%1" %~2

(This is XP.) I've also tried it with the last argument as %*, same error.

Any ideas? Have I totally confused you?
User avatar
Jan Paul
Posts: 21
Joined: Mon Apr 28, 2003 1:24 pm
Location: The Netherlands

Post by Jan Paul »

Hi,

You can make a batchfile which then can contain the path.
You can place the batchfile in the same directory as Perl.exe, that path should be the same for all users.

Code: Select all

Command: c:\windows\system32\cmd.exe 
Parameters: /C "c:\perl\bin\startperl.cmd" $File
StartDirectory: $FileDir
(The StartDirectory is irrelevant in this case).

The batch file (startperl.cmd) could look like this:

Code: Select all

@ECHO OFF
c:\perl\bin\perl.exe "%SCRIPT_PATH%\script.pl" -switch1 -switch2 "%*"
Be sure to have the SCRIPT_PATH as an environment variable in XP or use:

Code: Select all

@ECHO OFF
IF EXIST "%SCRIPT_PATH%\script.pl" c:\perl\bin\perl.exe "%SCRIPT_PATH%\script.pl" -switch1 -switch2 "%*"
Offcourse this is only an example.

Regards,
Jan Paul
User avatar
AntiEntropy
Posts: 11
Joined: Sat Sep 20, 2003 12:28 am

Post by AntiEntropy »

Thanks for your suggestion. It's certainly a good one, and one I tried, but too many of the scripts rely on the current directory being correct. And if I put all these batch files in the correct directory, how have I changed anything?

I'm more interested in how, from a technical point of view, TextPad launches the tools. I am a programmer so you can talk programeze to me. If TP launches a program called "script.pl" with parameters "-switch1 $File" and I get back a Perl error, something I don't understand is happening. If I can understand what TP is doing I may be able to configure it so that it works in a way best for my environment.

Right now I'm very frustrated and I'm going back to full paths to the scripts so please understand if I sound a little "pissy".

Thanks for your help.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

The current directory for a tool can be set.
It is called "Initial folder" in the Preferences dialog.

If you want to set it to the folder the current textpad file is in, you can use the tool parameters $FileDir.

Have a look at the complete list of parameter macros in
Help - Contents,
Reference Information - Tool Parameter Macros
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

AntiEntropy wrote:And if I put all these batch files in the correct directory, how have I changed anything?
In Jan Paul's suggestion, there is only one batch file. It's job is to be executed by your favourite command processor (e.g. cmd), which will replace any environment variables the file contains with their values, so that the correct path is searched for the perl script.
User avatar
AntiEntropy
Posts: 11
Joined: Sat Sep 20, 2003 12:28 am

Post by AntiEntropy »

I understand guys, I really do, and I appreciate the help. I tried the one-batch-file solution and it doesn't work for me. I'd have to pass in a different working directory for each file I work on which means changing all the scripts. These scripts are designed to work stand-alone and I was trying to get them to work with TP also.

Setting the working directory doesn't work either. I'm not sure why. That's why I'd like to know -- from a technical stand point -- what TP is doing when it launches a tool. If I knew this I might be able to figure out why all the things we think *should* work *don't*. I was hoping someone who knows the actual code would post here but if that's not possible I'll guess I'll post some specifics.

Maybe I should note that all these tools work fine when launched from vi.
User avatar
bbadmin
Site Admin
Posts: 879
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post by bbadmin »

Environment variables are expanded, if they are defiined in TextPad's environment space. For that to work, you must either define them using Control Panel/System/Advanced/Environment Variables, or assign them in a console window and start TextPad from that command prompt. In either case, the variables must be defined before TextPad is started. (Technically, TextPad inherits the environment space of its parent process.)

TextPad's own tool parameter macros can be used for a Perl script that is open in the active edit window. For example, $FileDir expands to the fully qualified path component of the script being edited.

I hope this helps.

Keith MacDonald
Helios Software Solutions
Post Reply