当我使用Java Bloomber V3 API时,它通常可以正常工作。但是,有时,特别是在重新启动后,bbcomm.exe没有在后台运行。我可以通过运行blp.exe手动启动它,但我想知道是否有办法通过API执行此操作?
我还在等帮助帮助...
答案 0 :(得分:4)
在与服务台交谈之后,事实证明在64位Windows上,在64位JVM下运行bbcomm并不会自动启动。这不会发生在32位Java下 - 32位bbcomm自动运行。
所以我的解决方案要么是等待Bloomberg解决问题(现在我理解了),要么检查这个具体案例。
检查具体案例:
os.arch
)java.vm.name
)下运行bbcomm.exe
未运行。尝试使用bbcomm.exe
Runtime.exec()
我还没有测试过上面的内容。它可能与彭博与64位虚拟机完全相同。
答案 1 :(得分:3)
在帮助帮助上花了一些时间后,似乎bbcomm在您使用Excel API或运行API演示时就会启动。但是从Java API调用时它不会自动启动。启动它的可能方法是:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
中添加一个名为bbcomm
的字符串值,其值为C:\blp\API\bbcomm.exe
- 但这会打开一个仍然可见的命令窗口,所以不是一个真正的选择(如果你关闭那个窗口它会终止bbcomm进程)START /MIN C:\blp\API\bbcomm.exe
并将注册表中的条目替换为(未测试)以静默调用bbcomm private final static Logger logger = LoggerFactory.getLogger(BloombergUtils.class);
private final static String BBCOMM_PROCESS = "bbcomm.exe";
private final static String BBCOMM_FOLDER = "C:/blp/API";
/**
*
* @return true if the bbcomm process is running
*/
public static boolean isBloombergProcessRunning() {
return ShellUtils.isProcessRunning(BBCOMM_PROCESS);
}
/**
* Starts the bbcomm process, which is required to connect to the Bloomberg data feed
* @return true if bbcomm was started successfully, false otherwise
*/
public static boolean startBloombergProcessIfNecessary() {
if (isBloombergProcessRunning()) {
logger.info(BBCOMM_PROCESS + " is started");
return true;
}
Callable<Boolean> startBloombergProcess = getStartingCallable();
return getResultWithTimeout(startBloombergProcess, 1, TimeUnit.SECONDS);
}
private static Callable<Boolean> getStartingCallable() {
return new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
logger.info("Starting " + BBCOMM_PROCESS + " manually");
ProcessBuilder pb = new ProcessBuilder(BBCOMM_PROCESS);
pb.directory(new File(BBCOMM_FOLDER));
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.toLowerCase().contains("started")) {
logger.info(BBCOMM_PROCESS + " is started");
return true;
}
}
return false;
}
};
}
private static boolean getResultWithTimeout(Callable<Boolean> startBloombergProcess, int timeout, TimeUnit timeUnit) {
ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, "Bloomberg - bbcomm starter thread");
t.setDaemon(true);
return t;
}
});
Future<Boolean> future = executor.submit(startBloombergProcess);
try {
return future.get(timeout, timeUnit);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
return false;
} catch (ExecutionException | TimeoutException e) {
logger.error("Could not start bbcomm", e);
return false;
} finally {
executor.shutdownNow();
try {
if (!executor.awaitTermination(100, TimeUnit.MILLISECONDS)) {
logger.warn("bbcomm starter thread still running");
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
<强> ShellUtils.java 强>
public class ShellUtils {
private final static Logger logger = LoggerFactory.getLogger(ShellUtils.class);
/**
* @return a list of processes currently running
* @throws RuntimeException if the request sent to the OS to get the list of running processes fails
*/
public static List<String> getRunningProcesses() {
List<String> processes = new ArrayList<>();
try {
Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
int i = 0;
while ((line = input.readLine()) != null) {
if (!line.isEmpty()) {
String process = line.split(" ")[0];
if (process.contains("exe")) {
processes.add(process);
}
}
}
} catch (IOException e) {
throw new RuntimeException("Could not retrieve the list of running processes from the OS");
}
return processes;
}
/**
*
* @param processName the name of the process, for example "explorer.exe"
* @return true if the process is currently running
* @throws RuntimeException if the request sent to the OS to get the list of running processes fails
*/
public static boolean isProcessRunning(String processName) {
List<String> processes = getRunningProcesses();
return processes.contains(processName);
}
}
答案 2 :(得分:0)
我们在使用.net API的Windows 7 64位计算机上遇到了同样的问题。 bbcomm.exe无法自动启动,唯一的解决方法是启动“Bloomberg API DEMO”应用程序......
答案 3 :(得分:0)
我知道这是一篇过时的文章,但我认为如果有人需要帮助从代码隐藏控制台窗口检查/启动 bbcomm.exe 进程,我会添加我的解决方案作为参考。
此代码段是用C#编写的,但我希望您可以轻松地将其翻译为Java。
void Main()
{
var processes = Process.GetProcessesByName("bbcomm");
if (processes.Any())
{
Console.WriteLine(processes.First().ProcessName + " already running");
return;
}
var exePath = @"C:\blp\DAPI\bbcomm.exe";
var processStart = new ProcessStartInfo(exePath);
processStart.UseShellExecute = false;
processStart.CreateNoWindow = true;
processStart.RedirectStandardError = true;
processStart.RedirectStandardOutput = true;
processStart.RedirectStandardInput = true;
var process = Process.Start(processStart);
Console.WriteLine(process.ProcessName + " started");
}
答案 4 :(得分:-2)
bbcomm.exe由V3 API自动启动。