⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleexerunner.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
字号:
/*
 * Created on Jun 25, 2006
 * @author Fabio
 */
package org.python.pydev.runners;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.eclipse.core.resources.IProject;
import org.python.pydev.core.Tuple;
import org.python.pydev.core.docutils.StringUtils;

public class SimpleExeRunner extends SimpleRunner{

    @Override
    public Tuple<String, String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) {
        String executionString = getCommandLineAsString(new String[]{script}, args);
        return runAndGetOutput(executionString, workingDir, project);
    }
    
    /**
     * Some notes on what has to be converted for cygwin:
     * - cygwin will accept both formats for the script
     * - PYTHONPATH, the paths MUST be in cygwin format
     * - In python, internally, all needs to be in cygwin paths.
     * 
     * below are the 'interactive' execution of python to validate what's written above.
     * 
     * 1. cygwin will accept both formats for the script:
     * 
     * >>c:\bin\cygwin\bin\python2.4.exe c:\temp\test.py
     * worked
     * >>c:\bin\cygwin\bin\python2.4.exe /cygdrive/c/temp/test.py
     * worked
     * 
     * 
     * 2. Now, for the pythonpath, the paths MUST be in cygwin format:
     * 
     * >>set pythonpath="c:/temp"
     * 
     * >>c:\bin\cygwin\bin\python2.4.exe /cygdrive/c/temp/test.py
     * /cygdrive/c/temp
     * /cygdrive/c/bin/4nt600/"c << yeap, here is the error. I have no idea why it happens.
     * /temp"
     * /usr/lib/python24.zip
     * ...
     * 
     * >>set pythonpath="/cygdrive/c/temp"
     * 
     * >>c:\bin\cygwin\bin\python2.4.exe /cygdrive/c/temp/test.py
     * /cygdrive/c/temp
     * /cygdrive/c/bin/"/cygdrive/c/temp"
     * /usr/lib/python24.zip
     * ...
     * 
     * 
     * In python, internally, all needs to be in cygwin paths:
     * print os.path.abspath(os.path.curdir)
     * will return /cygwin/c/bin
     * 
     * @param cygpathLoc the cygpath.exe location
     * @param paths the windows paths to be converted to cygwin.
     * @return a list of changed paths converted to cygwin.
     */
    public List<String> convertToCygwinPath(String cygpathLoc, String ... paths){
        for (int i = 0; i < paths.length; i++) {
            paths[i] = StringUtils.replaceAllSlashes(paths[i]);
        }
        ArrayList<String> ret = new ArrayList<String>();
        
        Tuple<String, String> output = runAndGetOutput(cygpathLoc, paths, (File)null, (IProject)null);
        if(output.o2 != null && output.o2.length() > 0){
            throw new RuntimeException("Error converting windows paths to cygwin paths: "+output.o2+".\nCygpath location:"+cygpathLoc);
        }
        if(output.o1 == null || output.o1.length() == 0){
            throw new RuntimeException("Unable to get the output.\nCygpath location:"+cygpathLoc);
        }
        StringTokenizer tokenizer = new StringTokenizer(output.o1, "\r\n");
        while(tokenizer.hasMoreTokens()){
            String tok = tokenizer.nextToken();
            ret.add(tok.trim());
        }
        
        return ret;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -