I need some help with a Java application which must run under Linux (Ubuntu) and this application must at some point (e.g. after pressing a button) run a .o program (in my case "disksim.o") with a number of parameters. Running the program from the terminal would look like this:
./disksim param1 param2 param3..........etc
I need this to be done automatically by a Java program.
Can anyone please give some tips about this issue?
When you have written a program in for example C or C++, there are two steps to make an executable program out of it: compiling and linking. The compiler takes your source code (*.c, *.cpp or something similar) and outputs an object file (*.o). That has to be linked (with a linker) to the necessary libraries into an executable program. So your *.o file is not a complete, runnable executable - you have to link it to get an executable.
Did you write that disksim program yourself, or do you have the source code for it?
GCC (the most used C and C++ compiler on Linux) can do compilation and linking in one step for you, if you call it the right way, for example (assuming you have the source file disksim.c):
DiskSim is a complex storage system simulation environment which can be used only in Linux. When you download it, you download only the sources and then you have to make it with gcc. Then the disksim.o file is genetated and you run it from terminal with ./disksim and some parameters. It reads an input file and generates an output file. Does this mean that it is already linked?
Also, I can only run it from it's own directory and I would like to run it from anywhere in the file system. Do you think is this possible and if it is, how do I do it?
Not only disksim.o is generated, but also the executable which is called disksim (without any extension) is generated. That's the executable, not disksim.o. If you are typing ./disksim, then you are running the executable in the file "disksim" in the current directory (not "disksim.o"). Note that "." means "current directory". If you want to run it from somewhere else, use the complete path, for example:
Or add the directory that contains the disksim executable to your PATH.
Forget about the disksim.o file. It's not the executable.
Joined: Nov 13, 2008
Yup, you're right about the disksim file. Don't know why I confused the executable with the .o file.
Can you please tell me more specifically how to run the file from another folder? I found that to create a new process you use:
If you could also please explain what the first 2 elements mean ("/bin/sh" and "-c"), 'cause I couldn't find anywhere the explanation.
I also found somewhere that in openSUSE (rpm-based) you can copy the executable anywhere and run it from there, or you can even copy it into root/bin folder and than run the program from anywhere in the file system without any constraints. I use Ubuntu which is deb-based and this doesn't work. Or does it and I am missing something?
And ofcourse for "/home/alex/somedirectory" you must substitute the full name of the directory that the disksim executable is in.
/bin/sh is the standard shell on Unix and -c is an option for sh that says "execute the commands following the -c" (which is in this case the command for running your disksim program).
Whether you can copy the executable anywhere and run it does not depend on whether the system uses RPM, DEB or some other packaging system. It depends on the program itself, and how it expects to find for example configuration files.