|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
Executing a c program
I've googled and searched, but can't find an answer to my first post here.
Using FreeBSD v7.0, I wrote a simple test program in c that just outputs a few lines of text to the screen. I discovered that the program apparently cannot be run from within the same directory where it resides. So, I moved it to /usr/local/bin, and now can execute it from my home directory. I'm using the JWM window manager, and put my c program into the JWM menu, but it won't execute from there. Both JWM and the program reside in /usr/local/bin. I'd like to be able to run the program either from the command line or from the JWM menu. I'm guessing I need to know the correct directory in which to put the program. Any help is appreciated. |
|
|||
How do you know that the command isn't executing from the JWM menu? All it does, you said, is output a few lines of text to the screen. So all it's doing is sending the text to STDOUT. If you don't have a terminal, STDOUT is either the terminal you started X from or your .xsession-errors file if you're using a display manager.
You probably want to add something like this to your JWM menu: 'xterm -e /usr/local/bin/your-program' |
|
|||
...did you compile said program? or just copy it over in source form? if so, compile it first.
To reiterate what adamk said, if the program is a simple text based application... running it via "JWM" won't produce any noticeable output, use xterm as demonstrated above. |
|
|||
Yes, I copied the compiled program to /usr/local/bin, and can run it from the command line. I tried xterm as suggested with no luck, but I'll keep toying with it.
|
|
|||
Quote:
#include <stdio.h> main() { system("clear"); printf("CD burning procedure\n\n"); printf("Before burning, test with the -t option\n\n"); printf("To burn CD: burncd -f /dev/acd0 -v -s 8 data <fname> fixrate\n\n"); printf("To erase CD : burncd -f /dev/acd0 blank\n\n"); printf("Files in /home/Ron:\n\n"); system("ls"); } Compiled with: cc <filename> Result is a.out - cannot execute this unless i move it to /usr/local/bin. Then can run from command line, but not from JWM menu. If I try to execute it drom that directory, it prints out all files in dir. I renamed it to Junk and then can run from command line, but not from /usr/local/bin Edit - after reading what I wrote it becomes clear that the JWM menu is executing a.out because the last line of my code is being executed - system("ls"); The files then overwrie what the program has put to screen. Also, it seems apparent that renaming the a.out file to Junk doesn't work. Last edited by Libran; 10th August 2008 at 04:07 PM. Reason: addition |
|
||||
Quote:
%echo $PATH then you need to add the dot to the beginning of that dir %./path/of/a.out Last edited by 18Googol2; 10th August 2008 at 04:05 PM. |
|
||||
Quote:
% cc source.c -o program Then execute program with: % ./program
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
|||
I'll bet he doesn't know to add the ./ in front or set the path.
|
|
|||
Don't think the problem is with ./ or path. I have no trouble running program. From the dir where it was compiled ./filename runs it. If I move the program to /usr/local/bin, I can run it from there with filename or ./filename. Only problem is that I can't get the JWM menu to execute it.
The jwmrc file is written in XML and is easy to edit. I have no trouble putting Firefox, Opera, etc in there. When i again tried inserting xterm -e /usr/local/bin/filename, as suggested, the output was just another xterm. Truth be known, I don't even want a desktop, just something to launch programs, and JWM seemed so simple. My sincere thanks to all of you who have tried to help me. |
|
|||
Quote:
|
|
|||
ocicat is correct, ask your yourself a question..
What does the program do? it executes a command.. prints some text.. executes another command, and then exits. Now, if you run this program from inside "JWM", where do you think the output is going? do you think it'll just magically open a window with the output you desire? On most POSIX systems, each program has a "terminal" tty attached to it(Unless it's a daemon.. syslog etc), and each program has 3 file descriptors, stdin, stdout and stderr. When you run that command without any associated terminal, the output/input are effectively sent to /dev/null. You can either delay the termination of the program with a sleep(3) call, or open an xterm and execute it manually. (Copying things over to /usr/local/bin is unnecessary, by default, the PATH environment variable sets $HOME/bin as a valid location for personal executables.). Last edited by BSDfan666; 11th August 2008 at 03:46 PM. |
|
||||
or you can use getchar like this:
#include <stdio.h> int main() { printf("CD burning procedure\n\n"); printf("Before burning, test with the -t option\n\n"); printf("To burn CD: burncd -f /dev/acd0 -v -s 8 data <fname> fixrate\n\n"); printf("To erase CD : burncd -f /dev/acd0 blank\n\n"); printf("Files in /home/Ron:\n\n"); system("ls"); puts("\n[Press any key to quit]"); getchar(); return(0); } $ cc -Wall -g -o program prog.c xterm -e /home/`id -nu`/program |
|
|||
I think I have it.
excerpt from .jwmrc: <Program icon="Opera.png" label="Opera">opera</Program> <Program label="Hello">xterm -e $Home/hello</Program> And it does need either sleep(x) or getchar() Thanks again to all who helped. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can't install program | guitarscn | OpenBSD General | 3 | 31st August 2009 08:40 PM |
A PDP-11 program card | TerryP | Programming | 0 | 10th April 2009 05:54 AM |
How to learn to program under BSD? | Sunnz | Programming | 5 | 24th December 2008 11:45 PM |
Learning how to program | Solaris_Delta | Programming | 9 | 24th December 2008 07:58 PM |
executing commands for all users when X starts with KDM | caesius | FreeBSD General | 2 | 20th October 2008 09:03 AM |