Advertisement

How to execute a command line by programming in Linux?

Started by March 29, 2007 08:12 AM
2 comments, last by adriano_usp 17 years, 9 months ago
Hi, I'm searching an way to execute a command line by programming in Linux. Please, take a look at the following example:

void PlayVideo(char *fileName)
{
	STARTUPINFO si;

	ZeroMemory(&si, sizeof STARTUPINFO); 
	si.cb          = sizeof STARTUPINFO;
	si.dwFlags     = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE; 

	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof PROCESS_INFORMATION);

	char CommandLine[200] = "mplayer.exe -f -loop 0 ";
	
	strcat( CommandLine, fileName );
	
	CreateProcess(  NULL,
			CommandLine,
			NULL,
			NULL,
			FALSE,
			IDLE_PRIORITY_CLASS,
			NULL,
			NULL,
			&si,
			&pi );

	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);
}

In the code above, I execute MPlayer in Windows using CreateProcess(). Please, how could I execute (by programming) the following command line in Linux? mplayer.exe -f -loop 0 fileName Thanks in advance
mplayer.exe

Run an *.exe file in Linux? But to answer your question, try the system() command.
--- ---Current Project: http://source.dev-null-productions.com/tw/"Perhaps the most fundamental problem, however, is that INTJs really want people to make sense."
Advertisement
The system call should work, or you can look into the fork/exec*/wait* functions if you want a bit more control.

The name of the executable in linux is mplayer (or gmplayer if you have the gui version installed)
Quote: Original post by Rhaythe
mplayer.exe

Run an *.exe file in Linux?

Ops... sorry. I had just copied/pasted the command line from the code and forgot to remove the extension. Thanks for the hint for using System().

Quote: Original post by pulpfist
The system call should work, or you can look into the fork/exec*/wait* functions if you want a bit more control.

Thanks, pulpfist.

This topic is closed to new replies.

Advertisement