我想在鉻嵌入式框架(C++)和另一個二進制之間啓用一些基本的IPC。我基本上想要從CEF啓動子二進制文件並通過管道進行通信。IPC之間的鉻嵌入式框架(C++)和另一個二進制
CEF似乎不支持將我們自己的代碼連接到已有的高級IPC。 它似乎沒有包含可用於在任意進程中啓動外部二進制文件的功能。 http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=12715
我想我正在尋找的是一個例子,你實際上連接兩個不同的二進制文件。
我需要將帶有字符串和命令的消息傳遞給二進制文件。這些命令和字符串將例如導致二進制初始化爲 ,使用cURL從URL獲取數據並銷燬它自己。
Soooo,看着這個我已經嘗試過使用一些基本的fork(),exec(),pipe()功能。 我得到的印象是,這是相當低的水平......
UPDATE:他們沒有在Windows工作,要麼,所以我切換到查看擴展/使用現有的CEF功能,見底
我需要根據一些狀態,init和destroy來控制子進程,以及處理來自它的狀態消息。
我已經設法產生一個二進制文件,下一步將創建一些基本的IPC 。 (fork(),exec(),pipe())是一種合理的方法來完成將CEF二進制文件與其他二進制文件集成的任務嗎?
//This codes fires of a binary, with some basic functionality in a separate process
printf("Parent PID %d\n",getpid());
signal(SIGCHLD, SIG_IGN);
pid_t pid=fork();
if (pid==0) { /* child process */
NSString *processString= [[NSString stringWithFormat:@"p %d",getpid()] autorelease];
static char *argv[]={(char*)[processString UTF8String],/*(char*)"echo",(char*)"Foo is my name.",*/NULL};
//execv("/bin/ps",argv);
execv("/Users/thisUser/Library/Developer/Xcode/DerivedData/mychildbinary/Build/Products/Debug/mychildbinary",argv);
exit(127); /* only if execv fails */
}
else { /* pid!=0; parent process */
//waitpid(pid,0,0); /* wait for child to exit */
}
這是一個基本的程序,寫入和讀取管道: http://www.gnu.org/software/libc/manual/html_node/Creating-a-Pipe.html
更新:
由於叉(),管()不適用跨平臺。我已經寫了LaunchExternalProcess方法,但是我仍然缺乏IPC的特徵,下面的代碼啓動一個外部進程從file_exe(完整路徑二進制):
// Test of process creation using CEF methods (static), might need to be moved.
void ClientHandler::LaunchExternalProcess(CefString file_exe) {
if (CefCurrentlyOn(TID_PROCESS_LAUNCHER)) {
// Retrieve the current executable path.
//CefString file_exe;
//if (!CefGetPath(PK_FILE_EXE, file_exe))
// return;
// Create the command line.
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::CreateCommandLine();
command_line->SetProgram(file_exe);
//command_line->AppendSwitchWithValue(cefclient::kUrl, url);
// Launch the process.
CefLaunchProcess(command_line);
} else {
// Execute on the PROCESS_LAUNCHER thread.
CefPostTask(TID_PROCESS_LAUNCHER,
NewCefRunnableFunction(&ClientHandler::LaunchExternalProcess, file_exe));
}
}
對這些過程之間的簡單通信的任何線索可以被製造?
我沒有得到PID或從LaunchExternalProcess方法什麼...