在NotePad ++中从其父目录运行批处理文件 [英] Run a batch file from its parent directory in NotePad++

查看:82
本文介绍了在NotePad ++中从其父目录运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个批处理文件,该文件标识了保留在该特定文件夹中的Java文件并进行编译.但是,当我从notepad ++运行该文件时,该批处理文件将转到notepad ++的工作目录(即C:\Program Files\Notepad++),然后启动,因此没有得到想要的输出.

I made a batch file that identifies java files kept in that particular folder and compiles them. But when I was running it from notepad++, the batch file was going to notepad++ working directory i.e. C:\Program Files\Notepad++, and then starting, so I was not getting desired output.

<Command name="Java_Executor" Ctrl="no" Alt="no" Shift="no" Key="0">&quot;D:\Projects\Java\Executor Java.bat&quot;</Command>

我尝试对其进行了多次编辑,但没有得到想要的输出.

I tried to edit it many times but didn't got desired output.

<Command name="second try" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /C &quot;cd /d D:\Projects\Java\ &amp;&amp; D:\Projects\Java\Executor Java.bat&quot;</Command>

这是我的第二次尝试.

这是第三次尝试:

<Command name="Java_Executor" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /k cd $(CURRENT_DIRECTORY) &amp;&amp; &quot;D:\Projects\Java\Executor_Java.bat&quot;</Command>

我应该编辑什么,以便批处理文件从它所在的同一文件夹运行? 假设我的bat文件为D:\Projects\Java\Executor Java.bat,其内容为:

What should I edit so that my batch file runs from the same folder where it is located? Assuming my bat file is D:\Projects\Java\Executor Java.bat with the contents of:

@ECHO OFF
color F0
ECHO                                        WELCOME TO EXECUTOR
ECHO                                                         -Garvit Joshi(garvitjoshi9@gmail.com)
ECHO                                                          USER:%USERNAME%
cd %cd% 
:first
ECHO LOOKING FOR FILES IN:%cd%
color F0
ECHO Name Of Java Executable Files Present In Folder Are:
python Filename_java.py
set /p "input=Enter The File You Want To Execute:"
ECHO ===============================
javac %input%.java
ECHO ===============================
ECHO Name Of Java Executable Class Present In Folder Are:
python Filename_class.py
ECHO ===============================
javac %input%.java
ECHO ===============================
set /p "input=Enter The Class You Want To Run:"
color 0A
ECHO ===============================
ECHO OUTPUT:
ECHO ===============================
java %input%
ECHO ===============================
color 0F
pause
ECHO =======================================================
ECHO *******************************************************
ECHO =======================================================
goto first

推荐答案

<Command name="Java Executor" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /k cd /d &quot;$(CURRENT_DIRECTORY)&quot; &amp;&amp; &quot;D:\Projects\Java\Executor Java.bat&quot;</Command>

第三次尝试似乎快到了.您要将目录从'C:/Program Files/Notepad++更改为D:\Projects\Java,在cd之后需要/d,否则就不会更改目录,因为它位于其他驱动器上.将$(CURRENT_DIRECTORY)用双引号引起来可能是个好主意,因为当前目录的路径可能带有特殊字符,即"D:\dogs & cats". Executor Java.bat在使用cd时显示相同的问题,因此其行为类似.

Third try seems almost there. You are changing directory from 'C:/Program Files/Notepad++ to D:\Projects\Java which will require /d after cd, else it will not change directory as to being on a different drive. Probably a good idea to enclose $(CURRENT_DIRECTORY) with double quotes as the current directory may have special characters with it's path i.e. "D:\dogs & cats". Executor Java.bat displays same issues with use of cd so it will behave similar.

测试脚本"D:\Projects\Java\Executor Java.bat"为:

@echo cd: "%cd%"

从Notepad ++的运行"菜单中的

运行Java Executor会显示带有以下内容的提示窗口:

Run Java Executor from Run menu of Notepad++ displays prompt window with:

cd: "D:\Projects\Java"

D:\Projects\Java>

使用cmd /k时提示已准备好输入.

The prompt is ready for input as cmd /k was used.

问题栏中的批处理文件中的行是:

In the batch-file in the question post is the line:

cd %cd%

我希望什么都不做,因为%cd%已经是当前目录.

I would expect that to do nothing as %cd% is already the current directory.

也许想将目录更改为脚本目录:

Perhaps wanting to change directory to the script directory:

cd /d "%~dp0"

查看for /?call /?有关诸如dp的修饰符.

View for /? or call /? about modifiers like dp.

这篇关于在NotePad ++中从其父目录运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆