Re: [Vala] Help writing to the terminal



On 30 June 2010 02:00, David LastName <lighteningstrike55 gmail com> wrote:
I'm trying to make a program to make what I have to type to compile
things shorter. It's so I can type: "/path/to/prog input.cc -o input"
instead of "g++ input.cc -o input -Wall -O2 `pkg-config xfcui-4.3
--cflags --libs`"
My problem is that g++ gives me an error saying that there's no such
file or directory for "`pkg-config xfcui-4.3 --cflags --libs`" So I
think my problem is that I don't know how to get the terminal to
execute the `pkg...` code and pass it to g++. I've tried running the
command first and saving the output in the array that's used to launch
g++, but I get the same error :(

Firstly, I agree with the other response saying that shell would be a
better language for this, or you could even just use an alias.

Beyond that, you definitely do need to execute pkg-config separately -
the bash trick of putting a command in `quotes` does just causes two
separate execs, so the raw launcher in glib won't be able to do it for
you automatically.

What you want to do is definitely possible, and I have done it
before[1], but it's probably not worth your time unless you really
want to do it.

Phil.

[1] http://bazaar.launchpad.net/~undeconstructed/realise/proto-1/annotate/head:/src/main/vala/tools.vala
- line 166ish

Here's my code:
public int main(string[] args)

{

       // Declare Vars

       int exit;

       string output = "", error = "";

       string[] pcon = {"/usr/bin/pkg-config", "xfcui-4.3", "--cflags", "--libs"};

       string[] cmds = new string[args.length+3];



       // Set Cmds

       for (int i = 1; i < args.length; i++) cmds[i] = args[i];

       cmds[0] = "/usr/bin/g++";

       cmds[args.length] = "-Wall";

       cmds[args.length+1] = "-O2";

       GLib.Process.spawn_sync(null, pcon, null,
GLib.SpawnFlags.STDERR_TO_DEV_NULL, null, out cmds[args.length+2],
null, null);

       //cmds[args.length+2] = "$(pkg-config xfcui-4.3 --cflags --libs)";



       // Run G++ and Exit

       GLib.Process.spawn_sync(null, cmds, null,
GLib.SpawnFlags.LEAVE_DESCRIPTORS_OPEN, null, out output, out error,
out exit);

       stdout.printf(output+error);

       return exit;

}


Thanks in advanced!
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]