LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Console commands && GUI (https://www.linuxquestions.org/questions/programming-9/console-commands-and-and-gui-62489/)

DaFrEQ 05-29-2003 10:01 AM

Console commands && GUI
 
Hey all...

What's the best/easiest way to grab a string of text, and throw it to console to be executed?

ex.
have a string that stores ls -aF and need to pass the variable to console to be executed as if typed in a console.

L8rz

fancypiper 05-29-2003 10:11 AM

Select the text you want by left clicking and dragging the mouse over it.

Middle click in the terminal.

DaFrEQ 05-29-2003 10:18 AM

ok... let me rephrase...
I have a GTK program. Small and pointless.
There is a text entry box that contains say: ls -aF
When I cilck btn_001 it will copy that strn to a var. From there I need it to be executed.

That's kinda what I meant. Not actually using the console.

Tnx.
L8rz

acid_kewpie 05-29-2003 10:25 AM

well you can't run it in a *different* console, you can start a console and run that command e.g.

system("aterm -e " . $widget->get_text);

in perl... you didn't say what language you're using though.

DaFrEQ 05-29-2003 10:30 AM

Oh sorry. Using C. Using Glade2 to put it all together.
Does glade handle perl?

But I think that's what I'm trying to do. I also don't know if I NEED to throw it to console.
How about something like:
click btn1 and it starts up the samba srv: /usr/local/bin/smbd -D

Kinda like that.. I guess.

Tnx for ur time BTW.

L8rz

acid_kewpie 05-29-2003 10:43 AM

well glade will generate all the callback stubs for you no problem, you just need to put the actual command you want to run inside the blank callback, so just build a string up from the variable and execute it with a system call.

acid_kewpie 05-29-2003 10:46 AM

yes glade2perl works on old gtk, that's how i started with http://acidrip.sf.net but i soon grew out of glade, far too limiting really especially as programming in Gtk really is very very simple after a little while.

DaFrEQ 05-29-2003 10:52 AM

Yeah it is. But I'm just trying to throw together a few simple things for tha boss before I go out on this job. He's sooo non linux... hell he's almost completely computer stpuid! heh...
anyway...

this is what I got as far as the proggie. I started out with a system command to handle the string but it doesn't look like it is being executed.
*********************************
{
GtkEntry *two;
GtkWidget * listitem;
gchar str[50];
gchar * p_str = str;
GtkWidget *dialog, *label, *okay_button;
char *text;

/* COPYING THE TEXT ENTERED IN ENTRY1 TO THE LIST WIDGET */
GtkWidget * entry = lookup_widget(GTK_WIDGET(button), "entry_002");
strncpy(p_str, gtk_entry_get_text(GTK_ENTRY(entry)),50);
listitem = gtk_list_item_new_with_label(p_str);

gtk_widget_show(listitem);

text = gtk_entry_get_text(GTK_ENTRY(entry));
two = GTK_ENTRY(lookup_widget(GTK_WIDGET(button), "entry_001"));

//printf("\nSAMBA COMMAND: %s", text);
system("%s", text);
//printf("\ntwo string : %s", two);
//printf("\nstr : %s", str);
}

DaFrEQ 05-29-2003 11:53 AM

sh: line 1: fg: no job control

is the output from the program when run with the code above (i.e. system call using the strn)

acid_kewpie 05-29-2003 11:56 AM

did you check the syntax for system() at all? it doesn't use the same format as printf, just a direct string

DaFrEQ 05-29-2003 12:00 PM

Yeah I was looking at that just now. I know the syntax isn't correct according to the mans, but I was just fiddling around with the string trying to figure out how to pass it to a system call.


All times are GMT -5. The time now is 06:19 AM.