Run program from any directory on Linux

Hi, I'm using a shell on a Sun computer to run a Java program.
The program requires the user to specify the name of an output file and and then an input file, manipulates the text in the input file, and prints it to the output file.
I would like to be able to run the program from any directory.
An IOException occurs if the input file is not in the same directory as the directory where you run the program.
If I have an input file which I want to manipulate in a different directory to where the actual program files are located (.java and .class), how do I specify that?
Thanks

When you execute a java program from a given directory, all relative file paths (i.e. foo.txt) are resolved using the current directory. You can most likely run the program from anywhere as long as you specify an absolute path to your files and have permissions to both read and write. I say most likely because you could be doing something incorrectly in your code.
If you want to run a program from anywhere, it must be:
1) on your PATH
2) be able to find its classes
An easy way to do that is write a small "wrapper" shell script and put that on your path.
I guaruntee you that a wise combination of terms used in this reply to compse a search engine query will yield you a useful tutorial or example.

Similar Messages

  • PE4-Win7: Please run this program from the Administrator account so it can set up your license. Once the license is set up, you can run it from any account.

    Hi,
    I'm using Premiere Elements 4 in Windows 7 (64 bit). When I launch PE I get the following error:
    Please run this program from the Administrator account so it can set up your license. Once the license is set up, you can run it from any account.
    Any idea how to solve it?

    I came across this link online. Please check it out and decide if it will or will not advance your case.
    http://www.howtogeek.com/howto/windows-vista/enable-the-hidden-administrator-account-on-wi ndows-vista/
    ATR

  • Can you run programs from time capsule? IE can I run microsoft office from it?

    can you run programs from time capsule? IE can I run microsoft office from it?

    Yes, probably can.. but it won't be fast. You are better storing programs locally and data remotely.

  • New Security Settings Prevents Running Pgm From Local Directory?

    I am an occassional Linux software author among other things, and have recently installed Arch 2007.08 (Don't Panic). Today I compiled and built one of my programs only to discover that Arch doesn't allow me to run it from its build directory. The usual
    ./progname
    produce the error:
    bash: permission denied
    BUT, if I copy the same executable to /usr/local/bin, it runs happily from there.
    I am guessing this is some form of new security mechanism that has been introduced. Can anyone enlighten me as to what this is? Is there a way to defeat it?
    By the way, I have tried this on the simplest of programs, the proverbial "hello world", so I know that my software isn't attempting to access files that it doesn't have permissions for. This seems to be a system wide thing.
    Any and all insights most appreciated!
    Last edited by mac57 (2007-09-03 20:06:07)

    Thanks, will do! I hadn't even considered that, since this is an ext2 volume...

  • Cant See RTF Files in JAR but can when running program from command prompt

    posted August 16, 2005 08:26 AM
    Hi ALL:
    I have a Java Swing APP. It has Menus which displays information through File I/O in a JEditorPane.
    When I run my program from Command Prompt using "java myApp" it shows these RTF Files as it is.
    However when I run them after converting Directory into a Executable JAR FILE, it fails. I get a blank JEditorPane. My RTF files are in the CORRECT PATH, just dont get displayed. Rest of the APP works fine.
    Chetan
    any suggetsions

    posted August 16, 2005 08:26 AM
    Hi ALL:
    I have a Java Swing APP. It has Menus which displays information through File I/O in a JEditorPane.
    When I run my program from Command Prompt using "java myApp" it shows these RTF Files as it is.
    However when I run them after converting Directory into a Executable JAR FILE, it fails. I get a blank JEditorPane. My RTF files are in the CORRECT PATH, just dont get displayed. Rest of the APP works fine.
    Chetan
    any suggetsions

  • Error using jar, but the programme works right when i run it from any IDE

    I have a programme with 25 .java archives. Is a GUI with a main panel and a JToolBar. When i run ir from Eclipse iDE, NetBeans or in the Linux shell it works rigth. Then i try to make a .jar. In the process i haven't any error, and when the application starts either. But when i click in some of the JMenuItems, they don't work. The function of this Items are change the main panel. It's like some .class of event listeners aren't included, but i check the .jar and has the same .class archives than the compiled project.
    What can be problem?? It's very urgent, please.
    Regards

    I'm so sorry for annoying you, i'm a poor stupid
    student that don't have money to hire an expert, so i
    try to learn and find help everywhere. But, don't
    worry, i resolve my problem by myself.what errors are you getting. It would be helpful if you could post the errors or some stack traces that you are getting

  • Strange message when trying to run program from outside IDE

    my java code runs fine from within borlands jbuilder IDE, but when i try to execute it from the command prompt i get an error message as follows.
    registry key 'software \javasoft\java run time envirnment \current version ' has value '1.4' but '1.2' is required
    does anybody know what this is about. all im doing is going to the directory i have my class files in then executing
    java program_name

    It sounds like you're running th 1.2 JVM on a machine that has a 1.4 JVM installed. Try using the java.exe command that was installed for 1.4 to run your application.

  • ItunesU videos not playing in Itunes but play ok if you download to laptop's drive and run them from windows directory

    I'm having a problem playing some ItunesU videos, some play okay, some just show black screen and don't play, others show a still image but then doesn't play when trying to view them from itunes store. The audio files play with no issues.
    I am using windows 7.
    However, if I download the videos that don't play to the laptop's drive and run them from the windows directory they play okay. I don't want to have to download videos to see if they are something I'd like to watch.
    Just for reference, an example of a video that plays okay is by UC Berkeley Math 16A 001, Fall 2011. Another is Introduction to Robotics by MIT.
    An example that just shows blank screen is Stanford's Iphone & Ipad development, Fall 2011, both HD and SD versions.
    While an example of a video that just shows the initial image but doesn't play is Harvard's Statistics 110. If you adjust the time of the video, the video moves to that part of the video but only shows the image at that time, ex. at 13:02, but doesn't play.
    I've tried reinstalling quicktime first, then itunes. I've also tried putting directdraw in safe mode, but the problem videos still won't play.
    Could it be some setting, since it plays when the file is downloaded but won't play straight from itunes store online (ie. pressing the play button beside the video in the itunes list).
    Help pls.

    You might have more luck asking on a general Windows troubleshooting site, but my guess would be an invalid or old audio or CD driver (or firmware in the drive). You might try checking those to make sure you have the correct and most current drivers.

  • How to run the java program from another directory?

    Hi
    Assumption:
    data.java is in a package suncertify.db and place in a directory c:/code/suncertify/db/ directory
    data.class file: is in c:/code/suncertify/db/ directory
    current directory: c:/
    How can execute the data.class directly in c:/ directory without changing directory to c:/code/ ?
    Thanks in advance,
    Adrian

    Yes. You can use the -classpath and -sourcepath options to specify where to look for source files, and the -d option to specify where to generate the class files. Look up the usage of those options in the javac documentation:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html

  • Can't run programs from non-admin account: redux

    Background: I have years of experience with PCs, very little with Macs. I work with children in a group home. The tech support people who set up this iMac (OS X 10.2) have long since departed, and no one in the organization has any clue as to what changes they made to this system, and I'm sure that those tech people made some changes. For example, in admin accounts other than "root," either there is no access to the Utilities folder or the folder has been well hidden.
    The Problem: The boys in this home will use a non-admin account. The programs I have installed for them will run under admin accounts but not under the "boys" account, which is non-admin. The system tells me that the account does not have enough access privileges to run the programs. (Program that had been installed before I got access to this iMac will run under the "boys" account.)
    In discussions on this forum several months ago, I thought the answers I got here had helped me solve the problem. Then, for administrative reasons, I did not touch the iMac until last week. What I thought had been solved is not solved.
    From "root," using the "Capabilities" option in the Accounts folder, I have added to the "Add other applications..." section the programs I want "boys" to have access to. But this doesn't work. When I log in to "boys," access is denied: insufficient access privileges.
    If I give up on this system, the boys will not be able to use this iMac, and that would be a shame.

    I realize that it sounds like I ignored all the previous advice before I drafted this latest post. But the first thing I did when I returned to the iMac was to look at the posts.
    I didn't touch the system for six months. I was waiting for approval from administration to upgrade the OS. By the time I got the approval, upgrading was no longer an option -- according to the manager of the local Genius Bar. This system is not capable of running 10.5, and Apple will no longer sell 10.4. I can find 10.4 on the Net, but those are private sellers and the price is too high.
    Now that I've got that out of the way, the current task: I have no idea why, but the gains I accomplished six months ago have disappeared. The "boys" account can run none of the software I installed. No one else has touched the system. (I live alone.)
    I logged on as "root" and went to Accounts. Using 10.2's Capabilities function, I tried to check all the boxes for "boys." But when I close the screen and then re-open it, the system has unchecked "Open all System Preferences"; "Change Password"; and access to "Utilities."
    At this point I cannot create new folders under "boys." "boys" can run software that was installed before I got the machine, but that's all.
    I have to assume that I inadvertently did something that wiped out my previous gains. But I ain't got a clue.

  • Running programs from disc

    hi, i have recently joined the apple mac revolution and bought myself a g4, it came with a programe called xbuntu which i do not want and have got OSX that i want to install.
    The problem is that when a put the disc in the dvd drawer it does not load automaticly and it does not give me the option to run the disc or anything along those lines.
    Please can someone help me with this as i'm starting to get really frustrated.
    Many Thanks!!!

    ok tell me what you OS you got on the HD now?
    Ubuntu Linux OEM means you got the LiveCD where it runs from a CD right? If so, all that does is allow you to see how Ubuntu runs on your Mac. Its not a true install its like Demo mode. You would have to do a full install to get the full effects of it. But thats a different topic for now...
    If you got OSX Panther NOW, you should be able to just put the Panther OSX CD into your Optical drive. Restart the Mac fresh power up.
    Press Option Key and keep holding it till you will get a Gray Screen with couple of Buttons on it. This screen will allow you boot your Mac from a Select volume, such as your HD or from the Panther OSX CD. Select the Panther CD and wait for the startup. Again it will be slow as its running of the CD. You should get your options to Install.
    When you get OSX Tiger its nearly the same process, except You Do Not Have to Install Panther first to use Tiger, You can Install Tiger fresh without Panther every being installed on your Mac. But If you Got Panther NOW, then Install it to your HD otherwise whats the Point of Having a Mac if all it does it sit there and take up space?
    BTW, do you what model your PowerMac G4 is? the specs you gave are sufficient, but more info is always good to know.
    I assume...based on what little you told me you may have one of the 1st generation 400MHz or 500Mhz G4 PowerMacs that first came with AGP graphics slot.
    good luck

  • Reading from home directory in linux using ~/ or $HOME and BufferedReader

    I'm working on an app that reads in a number from a user's home directory using BufferedReader. The file is written by an external script to ~/filename. I don't know if the user of the app's home directory will be /homes/username, /home/username, or something else. I would prefer to read in a similar fashion:
    BufferedReader in = new BufferedReader( new FileReader("~" + File.separator + ".AppDisableUntilDate") );
    Unfortunately, this causes the following error:
    java.io.FileNotFoundException: ~/.AppDisableUntilDate (No such file or directory)
    less ~/.AppDisableUntilDate does read the file. Using $HOME in place of ~/ also fails. Any ideas what might work?
    Thanks,
    Joel

    ~ is understood only by the shell. And not by every shell either.
    Korn and Bourne-again shell (ksh and bash) understand it, I would conjecture, Bourne shell (good old sh) does not.

  • How to run java from another directory

    hi,
    i have a Sample.java file in F drive(f:/Sample.java). I opened command prompt in windows and went to c: drive and try to compile as
    C:\>javac f:/Sample.java
    above command works well. it generated Sample.class file in F:/Sample.
    But, when i try to Run that file, i got the error as follow.
    C:\>java f:/Sample
    Exception in thread "main" java.lang.NoClassDefFoundError: f:/Sample
    Caused by: java.lang.ClassNotFoundException: f:.Sample
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: f:/Sample. Program will exit.
    Please guide me to run java file from another directory

    Thanks a lot. I appreciate your answer
    But, when i try to run the java program.. below message has been displayed, showing how to use the command with options....
    I didn't get the result of java program.
    c:\>java f:\Sample.java
    C:\>java -cp f:\Sample
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)
    where options include:
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    A ; separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:<value>
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
    enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:<libname>[=<options>]
    load native agent library <libname>, e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
    load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
    load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
    show splash screen with specified image
    C:\>

  • Can't run programs from non-admin account

    I'm new to the Mac and rusty with -- but not new to -- UNIX. I'm working with an iMac running OS X 10.2. I have installed several programs in a non-admin account (called "boys"), but they will not run from that account. The "get info" screen tells me that the "boys" account is the owner of the program. Read/write permission is enabled. When I try to run the programs, I get this error message: "The operation could not be completed because you do not have enough access privileges." I have installed the same programs in an admin account, and the programs run just fine from that account. I'd like to get this working so that the boys in the "boys" account can actually use the system. I have "inherited" this system from prior users. Programs that were on the system when I got my hands on it do run -- for the most part -- from "boys."
    iMac Mac OS X (10.2.x)
    iMac   Mac OS X (10.2.x)  

    Thanks for the reply, Ken. My various unsuccessful attempts to solve this problem led me to create a folder named "Programs." (I know, my PC roots are showing.) I did this for two reasons: 1) I hoped that this would give me more control over what was happening; and 2) I wanted to give the children with whom I am working an easy way to find the programs that I want them to use. When I use < cd /users/boys > and then do an ls- l, I see the Programs folder. An ls -l on that folder shows all the program I have loaded and indicates that the "x" permission is applied to owner, group and others. Moreover, I assumed (incorrectly, perhaps) that installing the programs using the "boys" non-admin account would make them the "owner" of the programs and that "x" permission would follow. Well, ls -l indicates that they are the owners and that they do have execute permission. I can only guess that the prior users of this system -- and nobody in this organization seems to know where they are -- did something that requires more than Advil to overcome.
    J...
    iMac Mac OS X (10.2.x)
    iMac Mac OS X (10.2.x)

  • How to execute program from any dir?

    For example javadoc.exe is in D:\jdk1.3\bin.
    And I need to execute it from current dir.

    If you are running a Javadoc from DOS or the WinNT command shell, the proper command is
    D:\JDK1.3\BIN\JAVADOC.EXE <params>
    If you want to avoid typing this each time, type the following at the command prompt:
    PATH=%PATH%;D:\JDK1.3\BIN
    The command JAVADOC.EXE will then function without specifying the directory. The proper action is normally to add the JDK to your PATH environment variable when installing it.
    In Windows 2000, you can modify your PATH variable by right-clicking My Computer and selecting the Advanced tab followed by the Environment Variables button. It is usually best to edit the PATH in the System Variables section to ensure that all users on your system receive the updated PATH variable.
    In Windows 95/98, I -think- that the appropriate action is to open your AUTOEXEC.BAT file and locate the last line that says PATH=<stuff>. Add the following to that:
    Old: PATH=C:\ADIR;C:\ANOTHER
    New: PATH=C:\ADIR;C:\ANOTHER;C:\JDK1.3\BIN
    I think this is appropriate for Win 95/98, but I'm not sure. Correct me if I'm wrong.
    Good luck!

Maybe you are looking for