using cd with output of external programm

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

using cd with output of external programm

Post by *dexli »

Hi all,

at the moment I have a button which starts a external program which puts the command eg. cd c:/temp/testdir into the clipboard. I have to switch to the commandline and use ctrl-c to copy this content. Than I have to hit return.

I'm looking for a method to feed the output which is not necessarily the clipboard but also a file or simply written to stdout.

The easyest way I suppose is a kind of substitute like in bash
CD $(prg to execute)
where first the prg_to_execute will executed and its output feed to CD

Is there such a mechanism in TC ??
Also other solutions are greatly appreciated!
User avatar
Sir_SiLvA
Power Member
Power Member
Posts: 3378
Joined: 2003-05-06, 11:46 UTC

Post by *Sir_SiLvA »

Learn to read the Helpfile of TC please.

Start TC -> Press F1 -> 4.a -> Params /L & /R are what you are looking for...
Hoecker sie sind raus!
User avatar
ts4242
Power Member
Power Member
Posts: 2081
Joined: 2004-02-02, 20:08 UTC
Contact:

Post by *ts4242 »

If you are the coder of the external program then you can do so via TC's command line, just run TC using a command line similar to this

Code: Select all

%COMMANDER_PATH%\TOTALCMD.EXE /O /L=your_prog_output
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

I don't understand exactly what you are searching for, but if you search a handy CD-Tool (change directory tool) for TC then take a look at "XCD":
http://mitglied.multimania.de/matbal/

Peter
TC 10.xx / #266191
Win 10 x64
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

Post by *dexli »

Hi Sir_SiLvA,

thanks for the quick reply.
Sir_SiLvA wrote:Learn to read the Helpfile of TC please.

Start TC -> Press F1 -> 4.a -> Params /L & /R are what you are looking for...
Maybe I'm a little bit unspecific because that is not what I'm asking for.

To make it clear:

TC is already runnig, than I click a button from the button bar. This action should start an external programm. Magicaly it generates a path to a directory. How can I force the running TC to change to this directory ??

Hope this is clear enough to prevent unecessary work ;-)

have fun
Dexli
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I think dexli needs another thing - he asked how to use output of one program as input for another.

It may be done using following way:

1. redirect output path to temporary file:

Code: Select all

input.exe > %temp%\my_new_path.txt
2. read temp file to envvar:

Code: Select all

set /p my_new_path= < %temp%\my_new_path.txt
3. use envvar to change dir in TC (parameter /O tells to TC not to start new instance but to change dir in already started one):

Code: Select all

%COMMANDER_PATH%\TOTALCMD.EXE /O /L=%my_new_path%
Steps 2 and 3 must be done in single batch file.
Last edited by MVV on 2011-05-10, 13:58 UTC, edited 3 times in total.
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

Post by *dexli »

Hi ts4242,

thanks for your reply.
ts4242 wrote:If you are the coder of the external program then you can do so via TC's command line, just run TC using a command line similar to this

Code: Select all

%COMMANDER_PATH%\TOTALCMD.EXE /O /L=your_prog_output
as stated before, that is not what I'm looking for. I don't want to fire up another TC. I just want to force the active one to change the directory.

Have fun
Dexli
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

Post by *dexli »

Hi Peter,

Peter wrote:I don't understand exactly what you are searching for, but if you search a handy CD-Tool (change directory tool) for TC then take a look at "XCD":
http://mitglied.multimania.de/matbal/

Peter
Sorry but this functionality is included in TC ( the asterisk beneth the actual path) and this is not the thing.

Have fun
Dexli
User avatar
ts4242
Power Member
Power Member
Posts: 2081
Joined: 2004-02-02, 20:08 UTC
Contact:

Post by *ts4242 »

dexli wrote:as stated before, that is not what I'm looking for. I don't want to fire up another TC. I just want to force the active one to change the directory.
Using the param /O will prevent starting another TC instance.
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

Post by *dexli »

Hi MVV
MVV wrote:I think dexli needs another thing - he asked how to use output of one program as input for another.
Not quite correct. The output of the program should be used as the parameter for a TC command.

Eg. lets say I have a button and in the Command: field I use

CD c:\a\long\path\to\a\directory

Than every time I click this button TC will set the actual directory of the active window to c:\a\long\path\to\a\directory

What I'm looking for is to find a way to call an external prg to provide another path instead of c:\a\long\path\to\a\directory

If TC would provide a command substitution like the BASH one would use

CD $(c:\path\to\external\prg)

The mechanism would be:

first the c:\path\to\external\prg would be called and its out put would be used as (a) parameter(s) to CD which will be executed than.


I know that such a mechanism do not exist in TC but maybe something similar.

I hope now I made clear what I'm looking for.

Have fun

Dexli
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

Post by *dexli »

Hi Ts4242,
ts4242 wrote:Using the param /O will prevent starting another TC instance.
oops! I'll will try that immediately !

Thanks
Dexli
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You need to pass path to envvar and then to call TC with /O parameter. Also read about /S and /T parameters - sometimes they're useful too.

Also you may download little tool called TCMC and use it to change path in TC - it is small so should be loaded faster than temporary second TC instance.
dexli
Junior Member
Junior Member
Posts: 12
Joined: 2010-01-18, 09:55 UTC

Problem solved :lol:

Post by *dexli »

Hi all,

thanks for your help I have found a solution which completly sattify my needs. :lol:

to give back a litte here the skelleton of a perl script which will be called by a button from the button bar.

Code: Select all

#! /usr/bin/perl -w
# proof of concept for using external prg
# to change the actual director of total commander

# Because of the cygwin environment the $Run is 
# necessary.
my $Run = 'c:\Programme\cygwin\bin\run.exe ';

# Path to totalcommander
my $TC='c:\Programme\totalcmd\TOTALCMD.EXE ';

# get some input 
print "Clientnumber: ";
my $a = <STDIN>;
$a =~s/\r*\n//;

# construct the path consisting of 
# a const part and the input 
$p ='d:\Region\Customers\Client_'.$a;

# construct the string which should be executed
# instead of using /L= one can use /R= or just
# the path to a directory. Maybe it is a
#good idea to enclose the $p value in
#double quotes because they might
#contain spaces
# .'"'.$p.'"'

my $str = $Run .$TC .'/O /L='.$p;

#show what is passed to exec
print $str,"\n";

# at least doit
exec $str;
Additonal info:

I use the cygwin environment *, therefor I have to use run.exe to start a windows prg. Also the #! /usr/bin/perl shebang will be different if you are not running cygwin.

*http://www.cygwin.com/
edit: adding information about quoting the the path
Post Reply