1
/*******************************************************************************
2
* Copyright (c) 2012 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.ssh.proxy;
13
import java.io.OutputStream;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
22
import org.eclipse.linuxtools.ssh.proxy.Activator;
24
import com.jcraft.jsch.ChannelExec;
27
* @noextend This class is not intended to be subclassed by clients.
29
public class SSHCommandLauncher extends SSHBase implements IRemoteCommandLauncher {
30
private String errorMessage;
31
private SSHProcess fProcess;
34
* Creates a new launcher Fills in stderr and stdout output to the given
35
* streams. Streams can be set to <code>null</code>, if output not
38
public SSHCommandLauncher(URI uri) {
43
public Process execute(IPath commandPath, String[] args, String[] env,
44
IPath changeToDirectory, IProgressMonitor monitor)
45
throws CoreException {
46
StringBuilder cmd = new StringBuilder();
48
if (changeToDirectory != null)
49
cmd.append("cd " + changeToDirectory.toString() + "; "); //$NON-NLS-1$ //$NON-NLS-2$
51
cmd.append(commandPath.toString());
52
cmd.append(" "); //$NON-NLS-1$
53
for (String s : args) {
55
cmd.append(" "); //$NON-NLS-1$
59
ChannelExec channel = createChannelExec();
61
for (String s : env) {
62
String[] tokens = s.split("=", 2); //$NON-NLS-1$
63
switch (tokens.length) {
65
channel.setEnv(tokens[0], null);
68
channel.setEnv(tokens[0], tokens[1]);
71
Activator.log(Status.WARNING, Messages.SSHCommandLauncher_malformed_env_var_string + s);
75
channel.setCommand(cmd.toString());
77
fProcess = new SSHProcess(channel);
79
} catch (Exception e) {
80
errorMessage = e.getMessage();
87
public int waitAndRead(OutputStream output, OutputStream err, IProgressMonitor monitor) {
89
return IRemoteCommandLauncher.ILLEGAL_COMMAND;
91
return fProcess.waitAndRead(output, err, monitor);
95
* @see org.eclipse.cdt.core.ICommandLauncher#getErrorMessage()
98
public String getErrorMessage() {