LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2003, 10:01 AM   #1
DaFrEQ
Member
 
Registered: Mar 2002
Location: Earth... for now
Distribution: SuSE9.2 AMD64; LFS; GentooAMD64; Ubuntu10.04; RHEL 5.5; Solaris10(SPARC)
Posts: 418

Rep: Reputation: 30
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
 
Old 05-29-2003, 10:11 AM   #2
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 60
Select the text you want by left clicking and dragging the mouse over it.

Middle click in the terminal.
 
Old 05-29-2003, 10:18 AM   #3
DaFrEQ
Member
 
Registered: Mar 2002
Location: Earth... for now
Distribution: SuSE9.2 AMD64; LFS; GentooAMD64; Ubuntu10.04; RHEL 5.5; Solaris10(SPARC)
Posts: 418

Original Poster
Rep: Reputation: 30
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
 
Old 05-29-2003, 10:25 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 05-29-2003, 10:30 AM   #5
DaFrEQ
Member
 
Registered: Mar 2002
Location: Earth... for now
Distribution: SuSE9.2 AMD64; LFS; GentooAMD64; Ubuntu10.04; RHEL 5.5; Solaris10(SPARC)
Posts: 418

Original Poster
Rep: Reputation: 30
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
 
Old 05-29-2003, 10:43 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 05-29-2003, 10:46 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 05-29-2003, 10:52 AM   #8
DaFrEQ
Member
 
Registered: Mar 2002
Location: Earth... for now
Distribution: SuSE9.2 AMD64; LFS; GentooAMD64; Ubuntu10.04; RHEL 5.5; Solaris10(SPARC)
Posts: 418

Original Poster
Rep: Reputation: 30
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);
}
 
Old 05-29-2003, 11:53 AM   #9
DaFrEQ
Member
 
Registered: Mar 2002
Location: Earth... for now
Distribution: SuSE9.2 AMD64; LFS; GentooAMD64; Ubuntu10.04; RHEL 5.5; Solaris10(SPARC)
Posts: 418

Original Poster
Rep: Reputation: 30
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)
 
Old 05-29-2003, 11:56 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
did you check the syntax for system() at all? it doesn't use the same format as printf, just a direct string
 
Old 05-29-2003, 12:00 PM   #11
DaFrEQ
Member
 
Registered: Mar 2002
Location: Earth... for now
Distribution: SuSE9.2 AMD64; LFS; GentooAMD64; Ubuntu10.04; RHEL 5.5; Solaris10(SPARC)
Posts: 418

Original Poster
Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Japanese canna won't work : Warning: かな漢字変&am OrganicOrange84 Debian 3 06-30-2005 02:28 PM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM
console commands for gui actions pcandpc Linux - Newbie 2 05-16-2005 09:29 PM
[SOLVED] Bad font in GUI & Konkerer-OK in Moz & others sundry_50 Linux - Newbie 2 02-06-2005 06:16 AM
how to uninstall lilo & install grub without using gui & linuxconf? prav_284 Red Hat 1 11-28-2003 05:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration