Works from console but not when clicked in KDE


 
Thread Tools Search this Thread
Top Forums Programming Works from console but not when clicked in KDE
# 1  
Old 04-22-2007
Works from console but not when clicked in KDE

why is it that:

#include <sys/stat.h>
#include <stdio.h>



int main(int argc, char **argv)
{
mkdir("testDir", S_IRUSR|S_IWUSR|S_IXUSR);

return 0;
}


works from the console when i type ./a.out but when clicked on from a window manager, it does diddly squat??? Interested to hear your answers.

Regards,
Jason.
# 2  
Old 04-22-2007
My guess would be that it worked but you don't know where it worked. Or that it failed because testDir already exists.

But why guess? You are susposed to check the return code from a system call. If the system call fails, you will get -1 and errno will be set to a value describing what went wrong. You should put code in your program to display the error code.
# 3  
Old 04-22-2007
1. What is the current directory when the program runs?

2. write a syslog or /tmp/myerror.log from the program to say what happened

3. try "perror()" as in

if (mkdir(.....)) { perror("mkdir failed\n"); exit(1); }
# 4  
Old 04-22-2007
Quote:
My guess would be that it worked but you don't know where it worked. Or that it failed because testDir already exists.
After reading that I did a search and lo and behold, when I execute from the console, testDir is created in the current directory. When executed from KDE, it creates the directory but in ~/ !!!


Quote:
try "perror()"
Thanks very much for pointing me to that function. It's really very useful. It actually tells you why something works or doesn't!

(just to clear things up, I am totally new to system programming being a java programmer... I have dabbled in Fortran but wanted to tackle Unix and C so here I am slaving away with a really really thick book... :-) Thanks for your patience.)

So my next question is:
Why on earth does it begin executing from home when it's clicked from another directory? Seems like a weird thing to do. Is their a function that can test where it was clicked from and to then change to that dir so it is now current?

You guys have been very helpful. Thanks.
Jason.
# 5  
Old 04-22-2007
Quote:
You are susposed to check the return code from a system call
Thanks for pointing that out by the way. I had wondered the reason for all the if(systemcall(...) ) in my book. Thought they were kinda overkill but when I kept getting -1 from it that prompted me to check for the testDir and I found it in ~/
# 6  
Old 04-22-2007
Quote:
Originally Posted by jasonkb
Why on earth does it begin executing from home when it's clicked from another directory? Seems like a weird thing to do. Is their a function that can test where it was clicked from and to then change to that dir so it is now current?
Say click on a program in /bin should the current directory be /bin?

NB: UNIX programs by themselves know *nothing* about KDE.

I suggest you look at what you are trying to do and work out is creating a directory in the same directory as the program a good idea? Unix programs normally separate out code from config from data. You also need to deal with multiuser issues, what happens if two people run the program at exactly the same time? If this is supposed to be a temporary directory why not create it in /tmp, /usr/tmp or $TMP ?
# 7  
Old 04-23-2007
Quote:
I suggest you look at what you are trying to do and work out is creating a directory in the same directory as the program a good idea?
Well I guess this is a problem. I don't have a specific thing that I am trying to do- just learning how all this works for now, with the unfortunate beginning from a Java developers perspective (there are some major differences although much is similar). If I executed a Java application from clicking on it, the current directory is the execution dir, and it was simply possible to grab the execution path. However what you have said makes real sense- what if two people run at the same time??? Can't have two separate testDir. They would need separate directories to put results into located in their home directory. But say that the program had config files it had to read in-would make sense to put them in the same directory as the executable...

Seeing as I am not anywhere near that level yet to even begin thinking of these matters or working on my app I am writing no-brainers to learn how functions for the Unix environment work.

Still leaves me with the problem of determining where the program is actually located so I could read in config files... :-( I have used make and make install for other programs before. Can one rely on the installation directory being constant on all Unix systems should make be used? If so I'll find some stuff to read up on it. That way I could hard code the installation directory into the app... Much to learn... :-| I sense some frustration in your last post, sorry if these noob questions are getting on your nerves. If you have any tutorials on say program design in the Unix environment, you can post them I'll read them to hopefully ask more sensible questions.

Cheers
Jason.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

IP Console Vs Serial console.

Hi Gurus, Can some one explain me the difference between a IP console and a serial console. (1 Reply)
Discussion started by: rama krishna
1 Replies

2. Solaris

Trap signal on Window Manager "X" button clicked?

Well, my first post... thanks in advance! Can applications be notified of the X Window close (with "X" button) so the signal handler can run a cleanup process method? About the app: built with GNU C/C++ on Solaris 10, with WxWidgets. It is launched by a shell script as a background task. The... (2 Replies)
Discussion started by: HandsOGold
2 Replies

3. AIX

SSH login hangs, serial console works

Server, running AIX 6.1 developed strange problem when logging in via SSH -- ssh client hangs without any error. It is possible to run commands on server, using ssh ("ssh servername ls -l" is OK) It is possible to log in normally, using serial console connected to server. It was possible to... (2 Replies)
Discussion started by: ivar.zarans
2 Replies

4. UNIX for Dummies Questions & Answers

Windows to Linux remote console using VNC brings up blank console screen with only mouse pointer

:confused:Hi This was installed on the Linux box a few weeks back by a guy that no longer works for us. All worked fine until last week. Now when we connect its just a blank screen with no icons. I get a whole bunch of errors when starting the service too: Tue Feb 23 14:29:45 2010 ... (1 Reply)
Discussion started by: wbdevilliers
1 Replies

5. Shell Programming and Scripting

how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable

hi, how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable which needs to be connected to one console server having rj11 on its side and db 9 female on other end.i.e. on switch side,console cable has rj45 and db 9 pin female connector on other side of... (1 Reply)
Discussion started by: pankajd
1 Replies

6. UNIX for Dummies Questions & Answers

KDE on Solaris ?

I want to install KDE on my Solaris PC , I downloaded solaris companion CD and question is there KDE available to install because I want that all my households work on one stable PC , but one condition is they must have K3B for burning files , and some GUI torrent program for downloading like Vuze... (2 Replies)
Discussion started by: solaris_user
2 Replies

7. UNIX for Advanced & Expert Users

console /dev/console get image

We are using software (Pegasys) which runs on SunOS 5.8 and reads images from a Philips nuclear camera. The software is designed to run from the console. I need to be able to capture the images it produces on the display. The caveat is that I cannot use the X Windows display because the X Server... (3 Replies)
Discussion started by: sreyes27
3 Replies

8. What is on Your Mind?

KDE names

I was kinda bored one day, so I renamed my files in KDE. Here are some examples: 1) I renamed my Hard Drive "Komputer" 2) I renamed my Trashcan to "Krap Bin" I'm kinda stuck on those two and I would like some suggestions on other file names. Please help a bored luser! ^_^ (1 Reply)
Discussion started by: gnerd
1 Replies

9. UNIX for Dummies Questions & Answers

How To...KDE on Solaris 8

I have my shinny new SunFire 280 server with a fresh copy of Solaris 8 installed. I installed the options CD which includes KDE. I can't seem to get it to work. (This is what happens when management gives a Unix box to an x86 Network Admin and says "Figure it out" ) I have played with Mandrake and... (1 Reply)
Discussion started by: RandySmith23
1 Replies

10. UNIX Desktop Questions & Answers

Kde 3.0

Hello, i,ve installed suse with kde 3.0, I had never used an X for unix before. So I don't know much. Most things were easy to find, but what anoyes me a lot is that the desktop is larger than mij monitor, so I have to move my mouse to see the rest of the desktop. I've tried to set the... (1 Reply)
Discussion started by: counTnegaTive
1 Replies
Login or Register to Ask a Question