You are not logged in.

Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, February 16th 2006, 3:18am

command line

I am not sure how best to implement the following.

I have an application that I want to be able to send files to via the command line or some other interface (DCOP ?). If the application is not running I want it to start and load the specified files, or if the application is running I want the running instance of the applicaiton to load the files.

Is this possible and if so what is the best approach?

Thx.

2

Thursday, January 18th 2007, 12:23am

RE: command line

Answer 1: the simple way. Just typed it from scratch so don't shoot me if it doesn't compile. Works with 99% of all platforms and can be associated with file ext. via OS to launch automatically. But wait there's more: you can also do some cool streaming stuff from the command line using the pipe operator.



#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
FILE *fp;

if( argc < 1 )
fp = stdin;
else
{
if( (fp = fopen(argv[1], "r")) == NULL);
{
printf("Unable to open file: %s\n", argv[1]);
return 1;
}
}
/* do what ever you want with the file or stream */


/* just make sure you close it : ) */
fclose(fp);
}