本文整理汇总了C++中ChildProcess类的典型用法代码示例。如果您正苦于以下问题:C++ ChildProcess类的具体用法?C++ ChildProcess怎么用?C++ ChildProcess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChildProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
void AppsPageComponent::startOrFocusApp(AppIconButton* appButton) {
if (debounce) return;
bool shouldStart = true;
int appIdx = runningAppsByButton[appButton];
bool hasLaunched = runningApps[appIdx] != nullptr;
String windowId;
if(hasLaunched) {
const auto shellWords = split(appButton->shell, " ");
const auto& cmdName = shellWords[0];
StringArray findCmd{"xdotool", "search", "--all", "--limit", "1", "--class", cmdName.toRawUTF8()};
ChildProcess findWindow;
findWindow.start(findCmd);
findWindow.waitForProcessToFinish(1000);
windowId = findWindow.readAllProcessOutput().trimEnd();
// does xdotool find a window id? if so, we shouldn't start a new one
shouldStart = (windowId.length() > 0) ? false : true;
}
if (shouldStart) {
startApp(appButton);
}
else {
focusApp(appButton, windowId);
}
};
示例2: getMainStack
void PowerPageComponent::buttonClicked(Button *button) {
if (button == backButton) {
getMainStack().popPage(PageStackComponent::kTransitionTranslateHorizontalLeft);
} else if (button == powerOffButton) {
showPowerSpinner();
child.start("systemctl poweroff");
} else if (button == rebootButton) {
showPowerSpinner();
child.start("systemctl reboot");
} else if (button == sleepButton) {
setSleep();
} else if (button == felButton) {
getMainStack().pushPage(felPage, PageStackComponent::kTransitionTranslateHorizontalLeft);
} else if(button == updateButton){
updateWindow->setVisible(true);
resized();
//Downloading rev number information
StringArray cmd{"wget", "-O", "version",
"https://drive.google.com/uc?export=download&id=0B1jRc4IqT9kiNC12WVpoUUtCRUE"};
ChildProcess download;
bool ok = download.start(cmd, ChildProcess::StreamFlags::wantStdErr);
if(!ok) printf("Process not launched\n");
else printf("Process launched !\n");
String output = download.readAllProcessOutput();
updateWindow->setMessage("Download successful !");
}
}
示例3: main
int main(int argc, char* argv[]) {
LDEBUG("address of notification procedure entry: %p",
ChildThread::processNotification)
// send a notification to let the parent know where the notification instruction is
ChildProcess::notifyParent(ParentNotification_Startup,
(long) ChildThread::processNotification);
// start the child process
ChildProcess child;
int ret;
try {
ret = child.main(argc, argv);
} catch (Exception &e) {
fprintf(stderr, "Exception occurred: %s\n", e.get_message().c_str());
e.print(2);
exit(1);
} catch (Exception *e) {
fprintf(stderr, "Exception occurred: %s\n", e->get_message().c_str());
e->print(2);
exit(1);
} catch (string &s) {
fprintf(stderr, "Exception occurred: %s\n", s.c_str());
exit(1);
} catch (const char* str) {
fprintf(stderr, "Exception occurred: %s\n", str);
exit(1);
} catch (...) {
fprintf(stderr, "Exception occurred \n");
exit(1);
}
LDEBUG("Exit value: %i", ret)
exit(ret);
}
示例4: DBG
void AppsPageComponent::focusApp(AppIconButton* appButton, const String& windowId) {
DBG("AppsPageComponent::focusApp - " << appButton->shell);
String focusShell = "echo 'focus_client_by_window_id("+windowId+")' | awesome-client";
StringArray focusCmd{"sh", "-c", focusShell.toRawUTF8()};
ChildProcess focusWindow;
focusWindow.start(focusCmd);
};
示例5: isPlatformDialogAvailable
bool FileChooser::isPlatformDialogAvailable()
{
ChildProcess child;
const bool ok = child.start ("which zenity")
&& child.readAllProcessOutput().trim().isNotEmpty();
child.waitForProcessToFinish (60 * 1000);
return ok;
}
示例6: exeIsAvailable
static bool exeIsAvailable (const char* const executable)
{
ChildProcess child;
const bool ok = child.start ("which " + String (executable))
&& child.readAllProcessOutput().trim().isNotEmpty();
child.waitForProcessToFinish (60 * 1000);
return ok;
}
示例7: jojo_doBang
void jojo_doBang (t_jojo *x, t_symbol *s, long argc, t_atom *argv)
{
ChildProcess process;
process.start ("ls /tmp"); /* All the job (fork, execv) is done there. */
/* IPC implemented with a pipe. */
StringArray processResult (StringArray::fromLines (process.readAllProcessOutput()));
for (int i = 0; i < processResult.size(); ++i) {
post ("%s", processResult.getReference (i).toRawUTF8());
}
}
示例8: reap_child
static void
reap_child(GPid pid, gint status, gpointer data)
{
ChildProcess *cp = data;
if (cp->callback) {
cp->callback(status, cp->data);
}
g_free(cp);
clean_pid();
wm->mode = GNT_KP_MODE_NORMAL;
endwin();
setup_io();
refresh();
refresh_screen();
}
示例9: runLameChildProcess
bool runLameChildProcess (const TemporaryFile& tempMP3, const StringArray& processArgs) const
{
ChildProcess cp;
if (cp.start (processArgs))
{
const String childOutput (cp.readAllProcessOutput());
DBG (childOutput); ignoreUnused (childOutput);
cp.waitForProcessToFinish (10000);
return tempMP3.getFile().getSize() > 0;
}
return false;
}
示例10: logOutput
void UnityProjectBuilder::saveProject (const File& introjucerAppFile)
{
if (! (introjucerAppFile.exists() || unityProjectFile.existsAsFile()))
return;
logOutput("Resaving Introjucer project...");
StringArray args;
args.add (getExeFromApp (introjucerAppFile).getFullPathName());
args.add ("--resave");
args.add (unityProjectFile.getFullPathName());
ChildProcess introjucerProcess;
introjucerProcess.start (args);
logOutput (introjucerProcess.readAllProcessOutput());
}
示例11: runTest
void runTest()
{
beginTest ("Child Processes");
#if JUCE_WINDOWS || JUCE_MAC || JUCE_LINUX
ChildProcess p;
#if JUCE_WINDOWS
expect (p.start ("tasklist"));
#else
expect (p.start ("ls /"));
#endif
//String output (p.readAllProcessOutput());
//expect (output.isNotEmpty());
#endif
}
示例12: previousWorkingDirectory
void FileChooser::showPlatformDialog (Array<File>& results,
const String& title, const File& file, const String& filters,
bool isDirectory, bool /* selectsFiles */,
bool isSave, bool /* warnAboutOverwritingExistingFiles */,
bool selectMultipleFiles, FilePreviewComponent*)
{
const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
StringArray args;
String separator;
// use kdialog for KDE sessions or if zenity is missing
if (exeIsAvailable ("kdialog") && (isKdeFullSession() || ! exeIsAvailable ("zenity")))
addKDialogArgs (args, separator, title, file, filters, isDirectory, isSave, selectMultipleFiles);
else
addZenityArgs (args, separator, title, file, filters, isDirectory, isSave, selectMultipleFiles);
args.add ("2>/dev/null"); // (to avoid logging info ending up in the results)
ChildProcess child;
if (child.start (args, ChildProcess::wantStdOut))
{
const String result (child.readAllProcessOutput().trim());
if (result.isNotEmpty())
{
StringArray tokens;
if (selectMultipleFiles)
tokens.addTokens (result, separator, "\"");
else
tokens.add (result);
for (int i = 0; i < tokens.size(); ++i)
results.add (File::getCurrentWorkingDirectory().getChildFile (tokens[i]));
}
child.waitForProcessToFinish (60 * 1000);
}
previousWorkingDirectory.setAsCurrentWorkingDirectory();
}
示例13: separator
void FileChooser::showPlatformDialog (Array<File>& results,
const String& title,
const File& file,
const String& filters,
bool isDirectory,
bool selectsFiles,
bool isSave,
bool warnAboutOverwritingExistingFiles,
bool selectMultipleFiles,
FilePreviewComponent* previewComponent)
{
const String separator (":");
String command ("zenity --file-selection");
if (title.isNotEmpty()) command << " --title=\"" << title << "\"";
if (file != File::nonexistent) command << " --filename=\"" << file.getFullPathName () << "\"";
if (isDirectory) command << " --directory";
if (isSave) command << " --save";
if (selectMultipleFiles) command << " --multiple --separator=" << separator;
command << " 2>&1";
ChildProcess child;
if (child.start (command))
{
const String result (child.readAllProcessOutput().trim());
if (result.isNotEmpty())
{
StringArray tokens;
if (selectMultipleFiles)
tokens.addTokens (result, separator, "\"");
else
tokens.add (result);
for (int i = 0; i < tokens.size(); i++)
results.add (File (tokens[i]));
}
child.waitForProcessToFinish (60 * 1000);
}
}
示例14: previousWorkingDirectory
void FileChooser::showPlatformDialog (Array<File>& results,
const String& title,
const File& file,
const String& /* filters */,
bool isDirectory,
bool /* selectsFiles */,
bool isSave,
bool /* warnAboutOverwritingExistingFiles */,
bool selectMultipleFiles,
FilePreviewComponent* /* previewComponent */)
{
String separator;
StringArray args;
const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
const bool isKdeFullSession = SystemStats::getEnvironmentVariable ("KDE_FULL_SESSION", String::empty)
.equalsIgnoreCase ("true");
if (exeIsAvailable ("kdialog") && (isKdeFullSession || ! exeIsAvailable ("zenity")))
{
// use kdialog for KDE sessions or if zenity is missing
args.add ("kdialog");
if (title.isNotEmpty())
args.add ("--title=" + title);
if (selectMultipleFiles)
{
separator = "\n";
args.add ("--multiple");
args.add ("--separate-output");
args.add ("--getopenfilename");
}
else
{
if (isSave) args.add ("--getsavefilename");
else if (isDirectory) args.add ("--getexistingdirectory");
else args.add ("--getopenfilename");
}
String startPath;
if (file.exists() || file.getParentDirectory().exists())
{
startPath = file.getFullPathName();
}
else
{
startPath = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
if (isSave)
startPath += "/" + file.getFileName();
}
args.add (startPath);
}
else
{
// zenity
args.add ("zenity");
args.add ("--file-selection");
if (title.isNotEmpty())
args.add ("--title=" + title);
if (selectMultipleFiles)
{
separator = ":";
args.add ("--multiple");
args.add ("--separator=" + separator);
}
else
{
if (isDirectory) args.add ("--directory");
if (isSave) args.add ("--save");
}
if (file.isDirectory())
file.setAsCurrentWorkingDirectory();
else if (file.getParentDirectory().exists())
file.getParentDirectory().setAsCurrentWorkingDirectory();
else
File::getSpecialLocation (File::userHomeDirectory).setAsCurrentWorkingDirectory();
if (! file.getFileName().isEmpty())
args.add ("--filename=" + file.getFileName());
}
ChildProcess child;
if (child.start (args))
{
const String result (child.readAllProcessOutput().trim());
if (result.isNotEmpty())
{
StringArray tokens;
if (selectMultipleFiles)
tokens.addTokens (result, separator, "\"");
else
//.........这里部分代码省略.........
示例15: ListenerThreadStatic
DWORD WINAPI ChildProcess::ListenerThreadStatic(LPVOID pVoidThis)
{
ChildProcess* pThis = static_cast<ChildProcess*>(pVoidThis);
return pThis->ListenerThread();
}