Start software from button bar in respect to actual dir

English support forum

Moderators: sheep, Hacker, Stefan2, white

wakatana
Junior Member
Junior Member
Posts: 15
Joined: 2016-05-25, 10:33 UTC

Start software from button bar in respect to actual dir

Post by *wakatana »

Hello. I've successfully set up button bar to being able use WinMerge and it works like a charm: when I click the button it compares two file which are selected under cursor. Here are settings:

Code: Select all

Command:     D:\portable\WinMergePortable\WinMergePortable.exe
Parameters:  /ub "%P\%N" "%T\%M"
Start path:  D:\portable\WinMergePortable\
Icon file:   D:\portable\WinMergePortable\WinMergePortable.exe

I'm using cygwin and my goal is to start bash in directory where I'm located, so far I have following settings:

Code: Select all

Command:     D:\portable\cygwin\rhcygwin\bin\mintty.exe
Parameters:  D:\portable\cygwin\rhcygwin\bin\bash.exe -l -c "cd \"%P\%N\"; exec bash"
Start path:  D:\portable\cygwin\rhcygwin\bin
Icon file:   D:\portable\cygwin\rhcygwin\bin\mintty.exe
This works but it does not open bash in directory where I'm located but rather the directory on which cursor is pointed. Also it seems that it is not working with all directories (I cannot prove it but I guess there was some issues maybe with long folder names or something else).


I'm also using software called R where I want same functionality as above: when R start from given directory it current working directory will become this directory, so far I have following settings:

Code: Select all

Command:     D:\portable\cygwin\rhcygwin\bin\mintty.exe
Parameters:  D:\portable\cygwin\rhcygwin\bin\bash.exe -l -c "cd \"%P\%N\"; exec r"
Start path:  D:\portable\cygwin\rhcygwin\bin
Icon file:   D:\portable\R-3.2.5\bin\i386\Rgui.exe

This works but it also opens terminal window which will remain active until I close R.

Changing parameters did not helped (R did not started):

Code: Select all

Parameters: D:\portable\cygwin\rhcygwin\bin\bash.exe -l -c "cd \"%P\%N\"; exec r &"

Is there any unified approach to this? I'm dreaming about some script that will call appropriate software based on parameters e.g.:

Code: Select all

Command:     D:\portable\some_magic_wrapper
Parameters:  D:\portable\cygwin\rhcygwin\bin\bash.exe
or

Code: Select all

Command:     D:\portable\some_magic_wrapper
Parameters:  D:\portable\r\r.exe

Thank you
User avatar
MVV
Power Member
Power Member
Posts: 8536
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Usually if you leave Start path field empty, TC starts program with current active directory as a starting directory.

However:
1. It depends on program if it will use its starting directory (e.g. cmd.exe does but notepad.exe doesn't).
2. Keep in mind that some programs don't work properly when started from a directory different from their own dirs (they cannot find their files).
3. When a program is started as administrator, starting directory parameter is ignored by Windows. So you have pass path in arguments if program supports it (e.g. for cmd.exe).
4. Since Windows Vista there are some stupid rules for initial directories of browse dialogs so working directory may be ignored by dialog ifself (it may open a folder that you've used last year instead).
wakatana
Junior Member
Junior Member
Posts: 15
Joined: 2016-05-25, 10:33 UTC

Post by *wakatana »

MVV wrote: Usually if you leave Start path field empty, TC starts program with current active directory as a starting directory.

However:
1. It depends on program if it will use its starting directory (e.g. cmd.exe does but notepad.exe doesn't).
2. Keep in mind that some programs don't work properly when started from a directory different from their own dirs (they cannot find their files).
3. When a program is started as administrator, starting directory parameter is ignored by Windows. So you have pass path in arguments if program supports it (e.g. for cmd.exe).
4. Since Windows Vista there are some stupid rules for initial directories of browse dialogs so working directory may be ignored by dialog ifself (it may open a folder that you've used last year instead).

Thank you for reply. I've tried start directly R (without Start path) and it worked. But bash does not. Any other suggestions?
User avatar
MVV
Power Member
Power Member
Posts: 8536
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

As I said, not all programs respect starting directory, so I think the only way with bash.exe is passing path to dir. However since it is under cygwin, it may have different path format for Windows paths (something like /cygdrive/c/Path) so you may need some script for converting path. You can also try Bash Prompt Here folder context menu tem (if it is in your Windows context menu) in order to see command line. Maybe these tips will be useful too.
wakatana
Junior Member
Junior Member
Posts: 15
Joined: 2016-05-25, 10:33 UTC

Post by *wakatana »

Biggest mystery for me is why changing this:

Code: Select all

Parameters:  D:\portable\cygwin\rhcygwin\bin\bash.exe -l -c "cd \"%P\%N\"; exec bash" 
To this:

Code: Select all

Parameters:  D:\portable\cygwin\rhcygwin\bin\bash.exe -l -c "cd \"%P\"; exec bash" 
does not works.
User avatar
Stefan2
Power Member
Power Member
Posts: 3014
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

 
As far as I remember, you do not have to quote \"%P\%N\" ,

and also %P comes with a trailing backslash on there on.

With that you get something like: ""D:\rive\path to\\app.exe""

Try
CMD: cmd /k
PARAM: "%P\%N"

on folders with and without spaces.



Use plain %P%N and %T%M instead, as TC add quotes themself if there are spaces in path.



Right?



 
User avatar
sqa_wizard
Power Member
Power Member
Posts: 3565
Joined: 2003-02-06, 11:41 UTC
Location: Germany

Post by *sqa_wizard »

BTW: Concerning WinMerge you may use it directly as default compare tool.
Just add a line to your wincmd.ini file:

Code: Select all

CompareTool=D:\portable\WinMergePortable\WinMergePortable.exe
This will compare files if they are in different or even selected in the same panel.
#5767 Personal license
User avatar
MVV
Power Member
Power Member
Posts: 8536
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Current directory is %P, not %P%N, and %P is not quoted by TC so quotes are required. But I don't know bash.exe syntax so can't tell is this command line is correct or not.
wakatana
Junior Member
Junior Member
Posts: 15
Joined: 2016-05-25, 10:33 UTC

Post by *wakatana »

OK, so are there any tricks that I can use for debugging those problems? So I can see why \"%P\%N\" is working and \"%P\" is not? Thank you
User avatar
MVV
Power Member
Power Member
Posts: 8536
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I've tried Git Bash Here which runs MINGW32 bash and I see following command line (I use Process Hacker as task manager):

Code: Select all

"D:\Program Files\Git\Git-2.5\git-bash.exe" "--cd=C:\Program Files (x86)\MSBuild\Microsoft\Expression"
So I've tried the following in TC and it works for me:

Code: Select all

Program: "D:\Program Files\Git\Git-2.5\git-bash.exe"
Parameters: "--cd=%P\"
Here I have to add extra backslash because %P ends with a backslash and git-bash escapes double quote after single backslash (very stupid unhandy feature) - maybe this is the trick you search for.
I think something similar should work for your CYGWIN bash.
wakatana
Junior Member
Junior Member
Posts: 15
Joined: 2016-05-25, 10:33 UTC

Post by *wakatana »

I've created debug_passed_argument.bat file with following content:

Code: Select all

@echo off
echo %1
@set /p pressedKey=Press any key to exit

This helped me to debug those problems. In totalcmd I've called this script as

Code: Select all

Command: D:\portable\cygwin\rhcygwin\debug_passed_argument.bat
with various parameters. Here are results:

parameters:

Code: Select all

\"%P\"
result:

Code: Select all

\"c:\Users\wakatana\Downloads\ST3\Data\Packages\bz2\\"
Press any key to exit
parameters:

Code: Select all

\"%P"
result:

Code: Select all

\"c:\Users\wakatana\Downloads\ST3\Data\Packages\bz2\"
Press any key to exit

So the correct button settings are:

Code: Select all

Command: D:\portable\cygwin\rhcygwin\bin\mintty.exe
Parameters: D:\portable\cygwin\rhcygwin\bin\bash.exe -l -c "cd \"%P"; exec bash"
Start path:
Icon file: D:\portable\cygwin\rhcygwin\bin\mintty.exe
Thanks all.
User avatar
MVV
Power Member
Power Member
Posts: 8536
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I've created debug_passed_argument.bat file with following content:
You can simply add a question mark at the beginning of Parameters field to enable confirmations for command line arguments. Also good task manager is very helpful here.
So the correct button settings are:
Yes, looks correct: trailing %P backslash escapes following double quote. :D
Great that it works!
wakatana
Junior Member
Junior Member
Posts: 15
Joined: 2016-05-25, 10:33 UTC

Post by *wakatana »

MVV wrote: You can simply add a question mark at the beginning of Parameters field to enable confirmations for command line arguments. Also good task manager is very helpful here.
Question mark trick is nice feature, thanks. But I do not get the point of good task manager. Mine problem was that bash immediately exits when the parameter was wrong. So I cannot check what argument was used during bash start or am I missing something?
User avatar
MVV
Power Member
Power Member
Posts: 8536
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Well, yes, that may be a problem if process exits immediately. Something like Process Monitor may be useful for such cases.
User avatar
ZoSTeR
Power Member
Power Member
Posts: 920
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

In Process Explorer you can set the Highlight Duration to a max of 9 seconds to see processes that immediately exit and then you can pause the updates with space.
Post Reply