如何从首选项页面获取路径并在按钮启动的过程中使用它?

时间:2023-01-12 15:59:07

I have made a preference page whose program code is --

我已经制作了一个偏好页面,其程序代码是 -

public class SAML
    extends FieldEditorPreferencePage
    implements IWorkbenchPreferencePage {

    public SAML() {
        super(GRID);
        setPreferenceStore(RmpPlugin.getDefault().getPreferenceStore());
        setDescription("Browse Appropriate files");
    }

    public FileFieldEditor f;
    public FileFieldEditor f1;
    public void createFieldEditors() {
        f = new FileFieldEditor(PreferenceConstants.P_PATH, 
                "&Prism.bat File:", getFieldEditorParent());
        addField(f);

        f1 = new FileFieldEditor(PreferenceConstants.P_PATH1, 
                "&NuSMV Application File:", getFieldEditorParent());
        addField(f1);
    }
    public void init(IWorkbench workbench) {
    }
}

In this preference page, there are two FileFieldEditor which is use to select "prism.bat" and "NuSMV.exe" file.

在此首选项页面中,有两个FileFieldEditor用于选择“prism.bat”和“NuSMV.exe”文件。

I have accessed path in my another button programming whose code is ---

我在另一个按钮编程中访问了路径,其代码是---

try {           
    IPreferenceStore store = plugin.getPreferenceStore();

    ProcessBuilder pb=new ProcessBuilder(store.getString(PreferenceConstants.P_PATH));
    pb.directory(new File(store.getString(PreferenceConstants.P_PATH)));
    Process p=pb.start();

    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String in;
    while((in = input.readLine()) != null) {
        out.println(in);
    }

    int exitVal=p.waitFor();            

   if(exitVal==0)
   {
        out.println("Printing on console");
   }
   else
       out.println("Process failed");
}
catch (Exception e)
{
    out.println(e.toString());
    e.printStackTrace();
}

Whenever I am clicking the button after selecting Prism.bat file from preference page, it says that file not found.

每当我从首选项页面选择Prism.bat文件后单击该按钮时,它会说找不到该文件。

What am I missing?

我错过了什么?

1 个解决方案

#1


0  

Debug your code and see what this computes to store.getString(PreferenceConstants.P_PATH)); pb.directory(new File(store.getString(PreferenceConstants.P_PATH))

调试你的代码,看看这个计算到store.getString(PreferenceConstants.P_PATH)); pb.directory(新文件(store.getString(PreferenceConstants.P_PATH))

excute it from the command line and see what is missing. My guess is that there is a space character in your path which is breaking it. Quotify the path may fix it. But see the string and decide accordingly.

从命令行执行它,看看缺少什么。我的猜测是你的路径中有一个空格字符可以打破它。 Quotify路径可能会修复它。但是看到字符串并做出相应的决定。

#1


0  

Debug your code and see what this computes to store.getString(PreferenceConstants.P_PATH)); pb.directory(new File(store.getString(PreferenceConstants.P_PATH))

调试你的代码,看看这个计算到store.getString(PreferenceConstants.P_PATH)); pb.directory(新文件(store.getString(PreferenceConstants.P_PATH))

excute it from the command line and see what is missing. My guess is that there is a space character in your path which is breaking it. Quotify the path may fix it. But see the string and decide accordingly.

从命令行执行它,看看缺少什么。我的猜测是你的路径中有一个空格字符可以打破它。 Quotify路径可能会修复它。但是看到字符串并做出相应的决定。