[英]Use Python script as external tool in IntelliJ IDEA
I'm using IntelliJ IDEA 14 Ultimate
and I'd like to run a Python script (in a Tomcat server) from within the IDE.我正在使用
IntelliJ IDEA 14 Ultimate
,我想从 IDE 中运行 Python 脚本(在 Tomcat 服务器中)。
I did it on Windows but it's not cross platform and I think it's a trick...我是在 Windows 上做的,但它不是跨平台的,我认为这是一个技巧......
This is what I did:这就是我所做的:
C:\\Python27\\python.exe
as ProgramC:\\Python27\\python.exe
定义为 PrograminitDB.py
initDB.py
Screenshot: New external tools屏幕截图:新的外部工具
It works well on Windows but I have to redefine this path on my other computers and my collaborators must do it too.它在 Windows 上运行良好,但我必须在我的其他计算机上重新定义这条路径,我的合作者也必须这样做。
So my question is: can I use a Python script as an external tool without specifying my script as a parameter
?所以我的问题是:我可以将 Python 脚本用作外部工具而不将我的脚本指定为
parameter
吗?
Thanks for the help.谢谢您的帮助。
There are a few things you can do to improve the situation a bit.您可以采取一些措施来稍微改善这种情况。
As described in Single script to run in both Windows batch and Linux Bash?如在Windows 批处理和 Linux Bash 中运行的单个脚本中所述? , it is possible to create a single script that you can run as a Windows batch file and as a Linux bash file.
,可以创建一个脚本,您可以将其作为 Windows 批处理文件和 Linux bash 文件运行。 You could for example create a file
/Freek/Scripts/initDB.cmd
with the following contents:例如,您可以使用以下内容创建文件
/Freek/Scripts/initDB.cmd
:
:; /usr/bin/python initDB.py; exit $?
C:\Programs\Python27\python.exe initDB.py
The definition of you external tool is stored in a well readable xml file.外部工具的定义存储在一个可读性良好的 xml 文件中。 For example, on my Windows laptop it is in the file
C:\\Users\\Freek\\.IdeaIC15\\config\\tools\\External Tools.xml
, which contains:例如,在我的 Windows 笔记本电脑上,它位于文件
C:\\Users\\Freek\\.IdeaIC15\\config\\tools\\External Tools.xml
,其中包含:
<toolSet name="External Tools">
<tool name="Test (Python)" description="Simple Python script" showInMainMenu="true"
showInEditor="true" showInProject="true" showInSearchPopup="true" disabled="false"
useConsole="true" showConsoleOnStdOut="false" showConsoleOnStdErr="false"
synchronizeAfterRun="true">
<exec>
<option name="COMMAND" value="/Freek/Scripts/initDB.cmd" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="/Freek/Scripts" />
</exec>
</tool>
</toolSet>
This file could be (partially) copied from one machine to another and does not contain any platform dependencies if you can decide on a common directory/link for all operating systems (like /Freek/Scripts
, which also works on Windows).如果您可以决定所有操作系统的公共目录/链接(例如
/Freek/Scripts
,它也适用于 Windows),则此文件可以(部分)从一台机器复制到另一台机器,并且不包含任何平台依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.