gVim gives [Permission Denied] when using --remote-silent - windows

I'm editing Unity 3D .cs files in gVim on Windows 7, I'd like when I double click a file in Unity for the file to open in an existing vim window, but instead it opens a new one.
To get around this I used various other SO answers to make a batch file and call vim using --remote-silent. This all works apart from vim acts like it wont allow remote commands to run on it.
Batch file:
#ECHO OFF
:Loop
IF "%1"=="" GOTO Continue
start "" "C:\Program Files (x86)\Vim\vim73\gvim.exe" --remote-silent ":sp %1<CR>"
SHIFT
GOTO Loop
:Continue
It gives me
":sp C:\my\path\file.cs" [Permission Denied] Press enter or type command to continue
I tried removing the "%1" to check if it was the file that was giving the permission error, but no luck. The batch file runs via a shortcut that runs as administrator (nothing is ever simple in Windows)
Unity -> Shortcut -> Batch file -> gVim -> ":sp filename"
Any ideas why vim won't let this command run?
Can't seem to find any mention of permissions in vim help -remote files or anyone else seeing this on google.
Thanks.
*Edit 1
Looks like something weird si going on, if I do :ls I see this in my buffer list
2 %a= ":sp C:\My\file\path.cs" line 1
Like its treating the whole command as the file path or something?

--remote-silent takes a file list, not Ex commands (well, you can pass one via +{cmd} before the files); that's why Vim interprets your command as a (non-existing) file.
Using --remote-send is the correct approach; like in the help examples, you should prepend <C-\><C-N> to ensure that the remote Vim is in normal mode (otherwise, if you've left it in insert mode, the commands would be inserted literally!)

I solved this myself after spotting the buffer issue.
I changed my batch to the following:
#ECHO OFF
:Loop
IF "%1"=="" GOTO Continue
start "" "C:\Program Files (x86)\Vim\vim73\gvim.exe" --remote-send ":sp %1<CR>"
SHIFT
GOTO Loop
:Continue
Looks like --remote-silent doesn't do what I thought it did.
I also added set shortmess=aoOtI to my vimrc to stop it prompting me.

Related

Can't open a .chm file from a batch file

I am trying to open a .chm file from a batch file.
The batch file has only this text in it :
echo off
start "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
If I run the batch file, the commandline opens but nothing further happens.
If I copy paste S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm in start menu/run then it does works.
If I make a shortcut with target "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm" then it also works.
So the command works everywhere, except from a batch file.
What am I doing wrong here ?
It might also be important to know that when I start it from the shortcut, or start menu/runI always get a dialog
We can't verify who created this file. Are you sure you want to open this file ?
I am using Windows 7
EDIT
My problem is not the dialog, my problem is that nothing happens when I open the chm file from a batch file
The Start command is probably seeing your doublequoted string as a title, enter Start /? at the command prompt for its usage information.
Try adding an empty title first:
#Echo Off
Start "" "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"

Calling batch file from original cmd works, but from .bat files doesn't

-BASIC INFORMATION
I have this sourceforge project called E-Series which makes certain coding tasks more easier, in this question I'll specifically be talking about "Easy Command Line" from E-Series.
-NOTES
-Once again, In the title as well, calling the batch file from original cmd (Access it by going to Run>cmd) does work, however calling it from a .bat file designed to call it does not.
-the batch file i'm calling has parameters.
-WHAT I'VE GOT
HERE are all the files required to run the whole program (download it if you want more specific information); note that when trying to type in my custom commands (Which you can see by typing help) such as "newfolder (name)" or "newfile (name and extension)" fails but calling it from cmd works. Just open command.bat for cmd if you downloaded it.
-WHAT I NEED
I need a .bat file that can "properly" call a batch file WITH parameters.
-WHERE DOES IT HAPPEN
-CALLING BATCH FILE FROM .bat file
I seriously recommend you download my program before going here, Or else it PROBABLY will not make ANY sense to you.
I have supposedly found out where the error happens;
#echo off
title Easy Command Line 0.1 E-Alpha
color a
:: The script is completely formatted in NotePad++ I recommend you use that when you're viewing the
:: Source code :)
:: This program is in extreme alpha say... 0.1 Alpha (Versions are counted every tenth (0.1),)
goto function_system_checkall
%clearcommand%
echo CONSOLE : Easy Command Line
echo CONSOLE : Type in "help" for a list of available commands. To enter batch mode
echo CONSOLE : type 'batchcommand'
:reset
set /p ecl_command="INPUT %cd%: "
if %ecl_command% == help goto help
if %ecl_command% == when echo %time%, %date%
if %ecl_command% == settings goto settings
if %ecl_command% == clear cls&goto reset
if %ecl_command% == clearscreen cls&goto reset
if %ecl_command% == cls cls&goto reset
if %ecl_command% == ping goto function_notyet
if %ecl_command% == checkall goto function_system_checkall
if %ecl_command% == navigate goto function_navigate
if %ecl_command% == debug #echo on
if %ecl_command% == disable_debug #echo off
call %ecl_command%
opening my program within debug mode (#echo on) shows that whenenver I type in "newfolder (name)" or "newfile (name & extension)" causes the output:
INPUT D:\Projects\easycommandline: newfolder 14
14 was unexpected at this time.
D:\Projects\easycommandline>if newfolder 14 == help goto help
ECL crashed!
Press any key to relaunch ECL. It is recommended to go into debug mode (type debug)
DETAILED SCREENSHOT
Which makes no sense. What does It mean with 14 was unexpected at this time.?
The method with my command parsing is first, it checks if the input corresponds to certain in-batch file commands such as "clear, cls, list, when, help" but in the very end, There's a "call" function because external programs are designed to handle directory (and more) actions such as creating a new folder, new file, etc.
-Calling batch file from cmd
As I've said, calling the batch file from CMD is FLAWLESS;
How can i fix this? getting really frustrated :( tell me if you need EVEN MORE information
In places where spaces can be included or a & character then you need double quotes:
Not this:
if %ecl_command% == help goto help
but this, and in all similar lines:
if /i "%ecl_command%" == "help" goto help
The /i makes the compare case insensitive.
Check encoding of your .bat file. When I used UTF-8, command prompt displayed error:
C:\Users\***\Desktop>´╗┐cmd
'´╗┐cmd' is not recognized as an internal or external command,
operable program or batch file.
When I used ANSI encoding, the .bat file worked as expected.

Gambit Scheme: gsi and gsc windows closes after end!

I'm experimenting with Gambit scheme and I have problem! My OS is Windows 7.
When I try to interpret script I do:
gsi.exe myscript.scm
This works, but GSI's console window is shown and closed just after script finished. I can't see results my program prints! I may do (read-line) at the end, but... when I try to compile with GSC.exe the behaviour is the same: it opens console window, does something, prints about errors and closes it immediately - I can't read something! In this case I can't even do (read-line) hack, you see. How can I view what Gambit writes?
This doesn't works, though:
gsc.exe 1.scm > 1.txt
You should run Gambit in an existing terminal window. Open up your terminal first, and then run Gambit. When Gambit terminates, your terminal will be still up.
Create a batch file with the commands. Set the properties on the batch file such that the window doesn't close after executing(right click, properties on the batch file's icon).
You can always, add "pause" at the end of the bath file, to keep the window open.
Alternatively, just open a DOSBOX box, and run the script from there. The box will remain open when the scrip completes.
UPDATE
terminal
To open a terminal(Command Prompt, DOS Box,etc.) use the [Start] button. Enter cmd in the "Run" field.
This will open a terminal with a command line interpreter. You can run gsc or gsi from there.
batch files
Here is the sample program hello.scm:
(display "HELLO WORLD")
(newline)
Method 1--using pause. This example is only for calling binary executable(.EXE) files such as gsc, or gsi.exe:
#echo off
gsi hello.scm
pause
Method 2--using cmd /k. The pause method (above) is preferred as this starts another cmd shell:
#echo off
cmd /k gsi hello.scm
properties
Sorry, setting the "Close on exit" property of a command apparently only exists for true DOS commands via .pif files.
To the same end right-click hello.scm, then associate it with cmd /k gsi hello.scm.
Any of the above batch files may be modified to take a filename argument (as %1, or %* for all args) and run gsc %1 instead of gsc hello.scm. After making the batch file generic in this way, associate the .SCM extension with it.
Associate .SCM with run-gsi.bat:
#echo off
gsi %*
pause

CMD Script: How to close the CMD

I have created a small command that will let me launch Internet Explorer. However, I wish to close the small command prompt that shows up when I launch IE. How can I do this? This is my current code:
"%ProgramFiles%\Internet
Explorer\iexplore.exe"
http://localhost/test.html
PAUSE
I am guessing if I take out the Pause. It will close the CMD box upon closing IE??
Also is there another command that I can use to simply create a command that will let me add something to the Menu with a small icon, which in turn runs the above. Is this complicated? Any tutorials I can use?
Thanks all
Use the start command:
start "title" "%ProgramFiles%\Internet Explorer\iexplore.exe" http://www.example.com
you need this on the end
&& exit
For example
"%ProgramFiles%\Internet Explorer\iexplore.exe" http://google.co.uk && exit
#echo off
start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "http://www.example.com"
exit /b
But you really should not force IE, but use the default browser:
#echo off
start http://www.example.com
exit /b
exit /b does not work on win9x IIRC, so if you need to support every version of windows and close the terminal window if the user double clicks your batch file, go with:
#echo off
start http://www.example.com
cls
You can also launch your program with the /c switch, which terminates the cmd once its finished executing
for example
cmd /c "%ProgramFiles%\InternetExplorer\iexplore.exe" http://localhost/test.html
You have to add 'start' in front of every program you launch, elsewhere your script is going to wait until it's finished.
A little late here, but running it in minimized mode or invisible mode might be another option. Source: https://www.winhelponline.com/blog/run-bat-files-invisibly-without-displaying-command-prompt/
Running .BAT or .CMD files in minimized mode
To run a batch file in a minimized window state, follow these steps:
Create a shortcut to the .BAT or .CMD file. To do so, right click on the file, click Send To, Desktop (create shortcut)
Right click on the shortcut and choose Properties
In the Run: drop down, choose Minimized
Click OK
Double-click the shortcut to run the batch file in a minimized window state.
"Mind the gap!"
Command Prompt always takes the empty space as separator, unless it's enclosed in double quotes.
So, if any Path, or Program/File Name, or anything includes empty space/es, must closed in quotes.
eg. "C:/Program files/..." path/directory or "Any Program/Command/File.exe/cmd/txt..." Program/Command/File Name includes space/es.
Syntax:
> start /?
Starts a separate window to run a specified program or command.
START ["title"] [/D path] (start swiches here...) [command/program] (com/prog-parameters here)
start "" /d "Drive:/the/Program/Path/..." "Command/Program Name.extension" "File-Name.extension"
So, it's usual fault:
If you don't set the 1st set of quotes "" for title (even if there's nothing to enclose), then the START command takes whats inside the 1st quotes set (eg. path! or Program Name!) and sets it as title... and of course, it messing up.

How to prevent auto-closing of console after the execution of batch file

What command can I put at the end of a batch file to prevent auto-closing of the console after the execution of the file?
In Windows/DOS batch files:
pause
This prints a nice "Press any key to continue . . . " message
Or, if you don't want the "Press any key to continue . . ." message, do this instead:
pause >nul
Depends on the exact question!
Normally pause does the job within a .bat file.
If you want cmd.exe not to close to be able to remain typing, use cmd /k command at the end of the file.
If you want cmd.exe to not close, and able to continue to type, use cmd /k
Just felt the need to clarify what /k does (from windows website):
/k : Carries out the command specified by string and continues.
So cmd /k without follow up command at the end of bat file will just keep cmd.exe window open for further use.
On the other hand pause at the end of a batch file will simply pause the process and terminate cmd.exe on first button press
If you are using Maven and you want to skip the typing and prevent the console from close to see the result you need to use the CALL command in the script, besides just the 'mvn clean install'.
Like this will close the console
ECHO This is the wrong exemple
mvn clean install
pause
Like this the console will stay open
ECHO This is the right exemple
CALL mvn clean install
pause
If you dont use the CALL command neither of the pasts exemples will work. Because for some reason the default behaviour of cmd when calling another batch file (which mvn is in this case) is to essentially replace the current process with it, unlike calling an .exe
The below way of having commands in a batch file will open new command prompt windows and the new windows will not exit automatically.
start "title" call abcd.exe param1 param2
start "title" call xyz.exe param1 param2
Add cmd.exe as a new line below the code you want to execute:
c:\Python27\python D:\code\simple_http_server.py
cmd.exe
my way is to write an actual batch (saying "foo.bat") to finish the job; then create another "start.bat":
#echo off
cmd /k foo.bat
I find this is extremely useful when I set up one-time environment variables.
Call cmd at the end of the batch file.
Had problems with the answers here, so I came up with this, which works for me (TM):
cmd /c node_modules\.bin\tsc
cmd /c node rollup_build.js
pause
besides pause.
set /p=
can be used .It will expect user input and will release the flow when enter is pressed.
or
runas /user:# "" >nul 2>&1
which will do the same except nothing from the user input will be displayed nor will remain in the command history.
This little hack asks the user to enter a key and stores it into the variable %exitkey% (this variable could be called anything you like though).
set /p exitkey= "Press any key to continue..."
NB: the space after the '=' is very important
I know I'm late but my preferred way is:
:programend
pause>nul
GOTO programend
In this way the user cannot exit using enter.
Possibility 1:
Just make 2 .bat files and write into the first:
start <filename> // name of 2nd batch file
exit
Batch file 2 is the file that wont close in the end.
So now when you open batch nr.1 It will start the 2nd and cloe itself.
When the 2nd finishes it will not close entirely (as long as you wont put exit at the end)
Possibility 2:
Batch file 1:
call <filename>
cls
echo End of file
pause
<any code you want>
When the 2nd file ends then it will proceed to file 1 again and output the rest of it. With that you can even make error handlers. If nr.1 crashes it goes into nr.2 and displays it
There are two ways to do it depend on use case
1) If you want Windows cmd prompt to stay open so that you can see execution result and close it afterwards; use
pause
2) if you want Windows cmd prompt to stay open and allow you to execute some command afterwords; use
cmd
pause
or
echo text to display
pause>nul
Easy, add cmd to your last line of bat, BUT! if you reset or clear your system path, you must start your cmd with the full path, like:
%windir%\system32\cmd.exe
For example, I have a bat file to reset jdk to old version like this:
PATH=C:\Program Files\Java\jdk1.6.0_45\bin;C:\apache-ant-1.7.1\bin
SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_45
%windir%\system32\cmd.exe
since I reset the system path, I have to run cmd with the full path, or the system can't find cmd.exe, it will fail to run cmd, and just close the window, and you can't see the error msg.
Run the .exe file and then pause the cmd
batch script example :
#echo off
myProgram.exe
PAUSE
batch script example with arguments :
#echo off
myProgram.exe argumentExample1 argumentExample2
PAUSE
I added #echo off because I don't want to show C:\user\Desktop>myProgram.exe and C:\user\Desktop>PAUSE in the cmd
cmd /k cd C:\Projects.....
If you want your cmd opened at specific long location
add pause (if you don't want anything else to show up add) >nul it should look like:#echo offtitle niceecho hellopause >nulall you will see is "hello"
I personally put pause >nul and it waits for a key to be pressed without showing any extra text in the console.
using : call yourbatch.cmd
does the job
will process the script and then continue ejecuting other code on same window (cmd instance)

Resources