简体   繁体   中英

How can I open the terminal and run shell commands in custom eclipse plugin like cp or mv?

I am new to eclipse development. Trying to create a plugin which will copy files from one directory to another. Introduced the menu as follows

样本菜单/复制文件菜单项

Now on click of the Copy Files menu I want to copy file/s. For that I want to run the command

cp file1.txt ../dir/file1.txt

I have handler as follows which will be executed once I click on menu.

public class SampleHandler extends AbstractHandler {
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        return null;
    }
}

How can I run the above command in my handler.execute() method to copy the files?

Consider reading and writing the files in your own code. Relying on external shell applications is not portable.

PlatformUI is the starting point to get the IWorkspace instance and get the source and target IFiles for your reading and writing. Use a combination of IFile#getContents() , IFile#create() , and IFile#setContents() to handle the actual I/O.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM