Invoke an third party application from a Juce application


#1

Hi,

I am looking for a JUCE class which can invoke a third party application from a JUCE application (in Windows OS).

My JUCE application sends some commands to the third party app, which will process the data and return results in form of a string.
I need to collect the data and process it.

Currently I am using “system” command to inovke the third party app from my JUCE app.
I am able to execute the third party app as expected.
But the problem is, whenever the third party app is invoked, a command window pops up.
Also I need to redirect the third party app’s output to a file and then read the file to check the output.
This is causing significant delay in the JUCE app execution.

Please suggest.


#2

I recently started writing a class to do that, but got interrupted and haven’t finished it yet, sorry!


#3

Thanks for the update.


#4

this is a beginning, It just starts a external process and check if its running.

Interface

class Process
{

public:
	Process(File _file): pfile(_file),proc_info(0)
	{
		
	};


	~Process()
	{
		winDeleteHandle(proc_info);		
	};

	bool start(String arguments)
	{
		winDeleteHandle(proc_info);
		String commandLine(pfile.getFullPathName()+" "+arguments);
		return winStartProcess(commandLine,proc_info);
	}

	bool isRunning()
	{
		if (proc_info!=0)
		{
			if (winIsProcessRunning(proc_info))
			{
				return true;
			}
		}
		return false;
	}
private:
	File pfile;
	void* proc_info;
};

Platform-Code

bool winStartProcess(wchar_t* commandLine, void*& processInfo   )
{
	DWORD dwCreationFlags = CREATE_NO_WINDOW;	// if Console application

	dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;

	HANDLE stdinHandle=0;
	HANDLE stdoutHandle=0;
	HANDLE stderrHandle=0;

	STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0,
		(DWORD)CW_USEDEFAULT, (DWORD)CW_USEDEFAULT,
		(DWORD)CW_USEDEFAULT, (DWORD)CW_USEDEFAULT,
		0, 0, 0,
		0,
		0, 0, 0,
		stdinHandle,stdoutHandle,stderrHandle
	};


	LPPROCESS_INFORMATION pinf=new PROCESS_INFORMATION;
	processInfo=(void*) pinf;

	BOOL ret = CreateProcess(0, commandLine,0, 0, TRUE, dwCreationFlags, 0 ,0,&startupInfo, pinf);

	return ret!=0;
}

bool winIsProcessRunning( void* processInfo   )
{
	LPPROCESS_INFORMATION pinf=(LPPROCESS_INFORMATION)processInfo;

	if (WaitForSingleObject(pinf->hProcess, 0) == WAIT_OBJECT_0)
	{
		return false;
	} else
	{
		return true;
	}
};


void winDeleteHandle(void*& processInfo   )
{
	LPPROCESS_INFORMATION pinf=(LPPROCESS_INFORMATION)processInfo;

	if (pinf!=0) {
		CloseHandle(pinf->hThread);
		CloseHandle(pinf->hProcess);
		delete pinf;
		processInfo = 0;
	}
};

#5

Is there a simpler way of invoking a windows executable from a JUCE application, without opening a command prompt or any information to the user that the JUCE application is invoking another application to do certain process.


#6

the method i mention opens no command-prompt (but is win-only), but of cause you will see in the task-manager/process-explorer that you app is invoking some other application.


#7

i did something like that for windows, it reads/writes data using pipes to stdin/out of the started process, i don’t know if it will work with the latest juce but the win32 code should work
the code is here: http://bazaar.launchpad.net/~vcs-imports/edo/trunk/files/head:/src/Components/EdoTunnel/old/


#8

Hi,

My application returns some string to the stdout as a result of executing the application.
If I a using the create Process function, how do I recieve the result string?