我有一个笔式驱动器:
目前我有一个批处理文件,用于“设置”cmd会话的环境变量,然后我运行cmd中的文件。现在显然这不是很理想,也不是很有效。
如何在Sublime Text 2中使用同一个笔式驱动器上的python可执行文件构建/运行文件,比如一个.py
文件?
更新
失败的尝试
F:\foo\SublimeText2_x64\Data\Packages\Build Systems\My Python.sublime-build
{
"working_dir": "$packages",
"cmd": ["cd ..\\..\\.. && setupenv && cd $file_path &&",
"python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell": true
}
这是我最终的结果:
{
"working_dir": "${packages}\\Build Systems",
"cmd": ["build.bat", "python", "$file_path", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
build.bat
(我打算为此添加更多语言,使其成为多语言构建文件)
@echo off
if "%1"=="" call :usage 0 & goto end
if "%2"=="" call :usage 1 & goto end
if "%3"=="" call :usage 2 & goto end
set my_dir=%~dp0\..\..\..\..
::------------------------- Setting Up the Environment -------------------------
:: Python
SET PATH=^
%my_dir%\PortablePython2.7.5.1\App;^
%my_dir%\PortablePython2.7.5.1\App\Scripts;%PATH%
:: Git
SET PATH=%my_dir%\Git\cmd;%PATH%
::------------------------------------------------------------------------------
pushd %2 :: Goto to the directory with the file
python -u %3 & goto end
:: ----------------------------------- Usage -----------------------------------
:usage
echo Error: Need 3 arguments (got %1)
echo Usage:
echo build.bat language file_path file
echo.
echo Arguments:
echo language : The language to build the file with
echo Supported languages - python
echo file_path : Path to the file
echo file : Name of the file (preferably with path)
goto end
::------------------------------------------------------------------------------
:end
popd
答案 0 :(得分:0)
语法错误,你应该创建一个从sublime接收两个参数的.bat文件,然后在.bat文件中进行所有处理。
F:\ foo \ SublimeText2_x64 \ Data \ Packages \ Build Systems \ My Python.sublime-build
的来源{
"working_dir": "path\\to\\your\\batch\\file",
"cmd": ["build-py.bat", "$file_path", "$file"]
}
批处理文件的来源
@echo off
setupenv
cd %1
python -u %2