You are not logged in.

#1 2011-05-03 01:47:58

Ron74
Member
Registered: 2010-01-24
Posts: 31

SOLVED Problem running a C program

The JWM window manager is configured by an XML file wherein you can insert a startup command as <Startup Command> command </Startup Command>.  I can start an application such as firefox here, but not a simple C program.

Here's an example:

/* Program beep */
#include<stdio.h>
int main(void)
{
system("beep");
return 0;
}

I can run this like ./beep, $HOME/beep, or because I put it into /usr/bin, either from the command line or from an xterm.  But, It won't run either from the JWM startup or from .xinitrc.  Apparently, I'm missing something in my code???

Last edited by Ron74 (2011-05-06 16:20:48)

Offline

#2 2011-05-03 02:07:26

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,324

Re: SOLVED Problem running a C program

I would suggest checking the file permissions first.
Second, I would check your .xinitrc to make sure there is not some program above it that does not return.  (Make sure they have a & appended to the end to ensure they are backgrounded)
Last, I am always suspicious about sound  at start up.  How about having the program touch a file as a cross check.

Last edited by ewaller (2011-05-03 02:11:48)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2011-05-03 02:13:07

Stebalien
Member
Registered: 2010-04-27
Posts: 1,239
Website

Re: SOLVED Problem running a C program

What is that program supposed to do. If you call it beep, and put it in /usr/bin (as you indicated) it will recursively call itself.

Last edited by Stebalien (2011-05-03 02:13:56)


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C

Offline

#4 2011-05-03 04:56:47

Ron74
Member
Registered: 2010-01-24
Posts: 31

Re: SOLVED Problem running a C program

ewaller,

The program has been made executable and permision set at 777.  Program runs, but cannot be started like any other application from the .jwmrc or the .xinit files as can other program files.  Reason I'm using sound, A simple "Hello World" won't show either. Neither will a script run when called this way.  No problem caused by lack of ampersand because there is no prior call to run a program.

Stebalien,

The example I showed is supposed to let me know that the program has executed by making a beep.   I tried doing Hello World, but nothing showed on screen. The simple example I show runs OK, just won't run from the startup command or from .xinitrc.

I'm trying to make a sort of front page for the window manager, but the c code must be started by the .jwmrc xml file.  I just can't a C program or a script to execute with the xml startup command.

Editing:  Could this be a problem with file permission?

Last edited by Ron74 (2011-05-03 05:13:30)

Offline

#5 2011-05-03 09:20:10

Badredin
Member
Registered: 2010-02-16
Posts: 2

Re: SOLVED Problem running a C program

You could try running the program using the full path, because the $HOME variable may not be set yet.

Offline

#6 2011-05-03 19:58:14

maddog39
Member
From: Philadelphia, PA
Registered: 2007-06-03
Posts: 73
Website

Re: SOLVED Problem running a C program

Ron74,

Okay, well Stabalien is correct, if you tried to put that program compiled as gcc beep.c -o beep and either put it or symlinked it into /usr/bin then not only did you possibly overwrite the actual beep command but, its now going to get in an infinite loop (due to recursion) and no system beep will ever get played. Anyway, that said, chmod a+x and use a hardcoded path instead of $HOME? Thats where I would start.

Last edited by maddog39 (2011-05-03 19:59:19)

Offline

#7 2011-05-04 01:54:59

Ron74
Member
Registered: 2010-01-24
Posts: 31

Re: SOLVED Problem running a C program

Badredin,
Had already tried that - doesn't work.

maddog39,
I now tried chmod a+x as you said with no difference in results.  I agree that the program could be looping.  I also have the simple Hello world that contains a getchar() so as to hold the output on screen.  Both these programs can be started with the xml startup command by using xterm /usr/bin/fname.  With hello World,  an xterminal appears with Hello World! being shown.  It waits for input, after which the window manager runs as it should. It seems obvious that my programs can be run from the command line and from an xterm, but not when called by the xml startup command which does work with firefox, thunderbird, etc.

Offline

#8 2011-05-05 17:05:48

listdata
Member
Registered: 2008-12-23
Posts: 102
Website

Re: SOLVED Problem running a C program

Ron74,

You shouldn't equate the startup behavior of bare-bones text C programs with full-fledged GUI programs like Firefox...

Trying to run your C program from .xinitrc will never succeed, because the .xinitrc file itself is called from a different shell session. I always start up my own console-based programs from within a terminal and background it (e.g., "urxvt -e program_path &") if I want .xinitrc to start it. You might want to try "urxvt -e program_path -hold" to let it keep the terminal + shell alive even after the program finishes executing.

Offline

#9 2011-05-06 16:20:03

Ron74
Member
Registered: 2010-01-24
Posts: 31

Re: SOLVED Problem running a C program

listdata wrote:

Ron74,

You shouldn't equate the startup behavior of bare-bones text C programs with full-fledged GUI programs like Firefox...

This had become apparent to me although I still am not fully aware of the technicalities.

Trying to run your C program from .xinitrc will never succeed, because the .xinitrc file itself is called from a different shell session.

Yes, and same for trying to call from the .jwmrc startup command.  The startup command is called by .jwmrc which is called by jwm itself.

I always start up my own console-based programs from within a terminal and background it (e.g., "urxvt -e program_path &") if I want .xinitrc to start it. You might want to try "urxvt -e program_path -hold" to let it keep the terminal + shell alive even after the program finishes executing.

Although I use xterm, i discoveded this by accident.

I will mark my post as solved.  Thanks to you and all others who responded.

Last edited by Ron74 (2011-05-06 16:24:36)

Offline

Board footer

Powered by FluxBB