本文整理汇总了Java中org.apache.felix.service.command.CommandSession.execute方法的典型用法代码示例。如果您正苦于以下问题:Java CommandSession.execute方法的具体用法?Java CommandSession.execute怎么用?Java CommandSession.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.felix.service.command.CommandSession
的用法示例。
在下文中一共展示了CommandSession.execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommandWithResponse
import org.apache.felix.service.command.CommandSession; //导入方法依赖的package包/类
public Object executeCommandWithResponse(String command) throws Exception {
// Run some commands to make sure they are installed properly
ByteArrayOutputStream outputError = new ByteArrayOutputStream();
PrintStream psE = new PrintStream(outputError);
ByteArrayOutputStream output = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(output);
CommandSession cs = commandProcessor.createSession(System.in, ps, psE);
Object commandOutput = null;
try {
commandOutput = cs.execute(command);
return commandOutput;
} catch (IllegalArgumentException e) {
Assert.fail("Action should have thrown an exception because: " + e.toString());
} catch (NoSuchMethodException a) {
log.error("Method for command not found: " + a.getLocalizedMessage());
Assert.fail("Method for command not found.");
} finally {
cs.close();
}
return commandOutput;
}
示例2: perform
import org.apache.felix.service.command.CommandSession; //导入方法依赖的package包/类
private void perform(final String commandLine) throws Exception {
if("shutdown".equals(commandLine)) {
context.getBundle(0).stop();
return;
}
ByteArrayOutputStream sysOut = new ByteArrayOutputStream();
ByteArrayOutputStream sysErr = new ByteArrayOutputStream();
final PrintStream printStreamOut = new PrintStream(sysOut);
final PrintStream printErrOut = new PrintStream(sysErr);
try {
final CommandSession commandSession = commandProcessor.createSession(System.in, printStreamOut, printErrOut);
Object result = commandSession.execute(commandLine);
if(result != null) {
printStreamOut.println(commandSession.format(result, Converter.INSPECT));
}
if(sysOut.size() > 0) {
LOGGER.log(Level.INFO, new String(sysOut.toByteArray()));
}
if(sysErr.size() > 0) {
LOGGER.log(Level.SEVERE, new String(sysErr.toByteArray()));
}
}
catch(Throwable ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
finally {
printStreamOut.close();
printErrOut.close();
}
}
示例3: executeCommand
import org.apache.felix.service.command.CommandSession; //导入方法依赖的package包/类
protected List<String> executeCommand(String command, CommandProcessor cp) throws Exception
{
boolean notfound;
int notfoundCounter = 0;
// Run some commands to make sure they are installed properly
ByteArrayOutputStream outputError = new ByteArrayOutputStream();
PrintStream psE = new PrintStream(outputError);
ByteArrayOutputStream output = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(output);
CommandSession cs = cp.createSession(System.in, ps, psE);
ArrayList<String> outputs = new ArrayList<String>();
do {
try {
cs.execute(command);
outputs.add(output.toString());
outputs.add(outputError.toString());
cs.close();
notfound = false;
} catch (CommandNotFoundException nfe) {
notfound = true;
notfoundCounter++;
if (notfoundCounter > 50) {
throw nfe;
}
Thread.sleep(200);
} catch (IllegalArgumentException e) {
// throw new IllegalArgumentException("Action should have thrown an exception because: " + e.toString());
notfound = true;
notfoundCounter++;
if (notfoundCounter > 50) {
throw e;
}
Thread.sleep(200);
} catch (NoSuchMethodException a) {
// log.error("Method for command not found: " + a.getLocalizedMessage());
throw new NoSuchMethodException("Method for command not found.");
}
} while (notfound);
return outputs;
}