mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added a new ChildProcess::start method that takes an argument array.
This commit is contained in:
parent
70ebb6f438
commit
98fcdca3ba
4 changed files with 51 additions and 12 deletions
|
|
@ -1000,7 +1000,8 @@ public:
|
|||
|
||||
Array<char*> argv;
|
||||
for (int i = 0; i < arguments.size(); ++i)
|
||||
argv.add (arguments[i].toUTF8().getAddress());
|
||||
if (arguments[i].isNotEmpty())
|
||||
argv.add (arguments[i].toUTF8().getAddress());
|
||||
|
||||
argv.add (nullptr);
|
||||
|
||||
|
|
@ -1069,12 +1070,15 @@ bool ChildProcess::start (const String& command)
|
|||
{
|
||||
StringArray tokens;
|
||||
tokens.addTokens (command, true);
|
||||
tokens.removeEmptyStrings (true);
|
||||
return start (tokens);
|
||||
}
|
||||
|
||||
if (tokens.size() == 0)
|
||||
bool ChildProcess::start (const StringArray& args)
|
||||
{
|
||||
if (args.size() == 0)
|
||||
return false;
|
||||
|
||||
activeProcess = new ActiveProcess (tokens);
|
||||
activeProcess = new ActiveProcess (args);
|
||||
|
||||
if (activeProcess->childPID == 0)
|
||||
activeProcess = nullptr;
|
||||
|
|
|
|||
|
|
@ -563,6 +563,11 @@ bool ChildProcess::start (const String& command)
|
|||
return activeProcess != nullptr;
|
||||
}
|
||||
|
||||
bool ChildProcess::start (const StringArray& args)
|
||||
{
|
||||
return start (args.joinIntoString (" "));
|
||||
}
|
||||
|
||||
bool ChildProcess::isRunning() const
|
||||
{
|
||||
return activeProcess != nullptr && activeProcess->isRunning();
|
||||
|
|
|
|||
|
|
@ -57,6 +57,15 @@ public:
|
|||
*/
|
||||
bool start (const String& command);
|
||||
|
||||
/** Attempts to launch a child process command.
|
||||
|
||||
The first argument should be the name of the executable file, followed by any other
|
||||
arguments that are needed.
|
||||
If the process has already been launched, this will launch it again. If a problem
|
||||
occurs, the method will return false.
|
||||
*/
|
||||
bool start (const StringArray& arguments);
|
||||
|
||||
/** Returns true if the child process is alive. */
|
||||
bool isRunning() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,18 +45,37 @@ void FileChooser::showPlatformDialog (Array<File>& results,
|
|||
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;
|
||||
StringArray args;
|
||||
args.add ("zenity");
|
||||
args.add ("--file-selection");
|
||||
|
||||
command << " 2>&1";
|
||||
if (title.isNotEmpty()) args.add ("--title=" + title);
|
||||
if (isDirectory) args.add ("--directory");
|
||||
if (isSave) args.add ("--save");
|
||||
|
||||
if (selectMultipleFiles)
|
||||
{
|
||||
args.add ("--multiple");
|
||||
args.add ("--separator=" + separator);
|
||||
}
|
||||
|
||||
const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
|
||||
|
||||
if (file.isDirectory())
|
||||
{
|
||||
file.setAsCurrentWorkingDirectory();
|
||||
}
|
||||
else if (file.exists())
|
||||
{
|
||||
file.getParentDirectory().setAsCurrentWorkingDirectory();
|
||||
args.add ("--filename=" + file.getFileName());
|
||||
}
|
||||
|
||||
args.add ("2>&1");
|
||||
|
||||
ChildProcess child;
|
||||
if (child.start (command))
|
||||
if (child.start (args))
|
||||
{
|
||||
const String result (child.readAllProcessOutput().trim());
|
||||
|
||||
|
|
@ -75,4 +94,6 @@ void FileChooser::showPlatformDialog (Array<File>& results,
|
|||
|
||||
child.waitForProcessToFinish (60 * 1000);
|
||||
}
|
||||
|
||||
previousWorkingDirectory.setAsCurrentWorkingDirectory();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue