Oh. My. God.
I just peed my pants. (^_^)
Notes of a software developer
This function takes the parameterspid_t
exec_redirect(
const char *path, char *const args[],
int new_in, int new_out, int new_err
)
{
pid_t child;
// Fork new process
child = fork();
if (child == 0) {
// Child process
// Redirect standard input
if (new_in >= 0) {
close(STDIN_FILENO);
dup2(new_in, STDIN_FILENO);
}
// Redirect standard output
if (new_out >= 0) {
close(STDOUT_FILENO);
dup2(new_out, STDOUT_FILENO);
}
// Redirect standard error
if (new_err >= 0) {
close(STDERR_FILENO);
dup2(new_err, STDERR_FILENO);
}
// Execute the command
execv(path, args);
}
// Parent process
return child;
}
path
and args
which is the same as what you would normally pass to execv(3)
. In addition, there are three parameters, new_in
, new_out
, and new_err
which are (optional) file descriptors where the new application's standard input, output, and error, respectively, will be redirected from/to. To make redirection optional, we specify that if the descriptor parameter is -1
, then no redirection will take place./bin/myapp -l -p
, with input redirected from in.txt
, output redirected to out.txt
, and error redirected to err.txt
:On a closing note, it's also probably a good idea to...
char *cmd = "/bin/myapp";
char *args[] = { "/bin/myapp", "-l", "-p", NULL };
in = open("in.txt", O_RDONLY);
out = open("out.txt", O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
err = open("err.txt", O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
exec_redirect(cmd, args, in, out, err);
...
close()
the file handles in the parent process, after exec_redirect()
, just to prevent "inadvertently" accessing them while the child process is also doing the same. Yes, the pun was intended ;-)org.example.ds
._0.ecore
). You can rename it if you want, like here I renamed it to ds.ecore
.ds.ecore
). Also, there will be a ds.genmodel
file which is a generator model for your model: it tells EMF about code-generator-specific stuff like where to put the generated files, what base package name to use, etc.ds.genmodel
file. It will open the GenModel editor:org.example
so that the generated package will start with org.example.ds
. And also rename the Prefix property to "Ds" (previously it was "_0")..edit
project which you can re-use outside of the Eclipse environment, and an Eclipse-specific .editor
project which is tightly bound to (you guessed it) the Eclipse environment..editor
plugin you just created, and show a nice tree-based editor for you!My.ds
using a text editor, you will see the underlying data is fully compliant XML!Tservice
, Tproperties
, and so on (fugly!). These are a direct consequence of the <complexType name="xxx">
declarations in the schema. It would be nice if the generated class names were more, hmm... how you say... Java-ish? :-p Like Service
and Properties
, respectively, for example.interface
, I don't want to type the Java interface name in a text box. I want something similar to those nice JDT dialogs where I can search and select for the Java interface: