LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-13-2011, 03:10 PM   #1
bigmac15
LQ Newbie
 
Registered: Jun 2011
Posts: 9

Rep: Reputation: Disabled
Using a .txt thats in a directory without specifying directory


Im working on a java application where my prof is going to use this exact line to run the application

Code:
java applications.TestMyDataReader  < MyDataReader1.txt
My problem is MyDataReader1.txt has to be in a directory named data. Is their a way you can add to the .bash_profile (im guessing) to look into directory "data"? Thats what i did with classpath for directory "classes"
 
Old 06-13-2011, 03:12 PM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello and Welcome to LinuxQuestions,

You should be aware that your prof might be a LQ user/visitor too and might not appreciate you asking us to do your homework for you. We would be glad to point you to errors in whatever you tried and is failing/erroneous but we will not provide you with ready made solutions. You'll learn a lot more when doing it yourself.

Looking forward to your participation in the forums. Have fun with Linux.

Kind regards,

Eric
 
Old 06-13-2011, 03:17 PM   #3
bigmac15
LQ Newbie
 
Registered: Jun 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Ive tried going into the .bash_profile and changing the path but that didnt work. Ive been searching through google without much success because im not sure what to search for.
 
Old 06-13-2011, 03:18 PM   #4
flakblas
Member
 
Registered: Jun 2009
Location: Maryland
Distribution: Fedora, CentOS, RHEL, Ubuntu
Posts: 41

Rep: Reputation: 3
I think that would only work if they are already in the data directory since the file is being specified explicitly.
 
Old 06-13-2011, 03:31 PM   #5
bigmac15
LQ Newbie
 
Registered: Jun 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
He's going to run the application from my base directory which has a subdirectory data though. The only way i could run that line and make it work is when i add data/MyDataReader1.txt instead of just the filename
 
Old 06-13-2011, 05:54 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,825

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
adding the $PATH in the ".bash_profile " for the user that is going to read the file will work
just log out and back in again

an example :for ScientificLinux 6.1
Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:/home/YOUR-USER-NAME/data:$HOME/bin
export PATH
and "/home/YOUR-USER-NAME/data" is the absolute PATH and NOT the relative PATH
 
Old 06-13-2011, 06:03 PM   #7
bigmac15
LQ Newbie
 
Registered: Jun 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
I tried that before (without $HOME/bin though) now i have:

Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:/home/mfaria-seerattan/data:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME=""

export USERNAME BASH_ENV PATH

export CLASSPATH="classes"
still saying
Code:
-bash: MyDataReader1.txt: No such file or directory
 
Old 06-13-2011, 10:32 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,825

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
did you log out then log back in

you must restart X for that to take affect

then type
Code:
echo $PATH
it should show

Last edited by John VV; 06-13-2011 at 10:34 PM.
 
Old 06-13-2011, 11:18 PM   #9
bigmac15
LQ Newbie
 
Registered: Jun 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Code:
/home/uli101/bin:.:/opt/oracle/11.2.0.0.0/bin:/usr/lib/mpi/gcc/openmpi/bin:/usr/                                             local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/cross/bin:/b                                             in:/usr/java/jdk/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/home/mfaria-seerattan/d                                             ata:/home/mfaria-seerattan/bin
its their but its not work when i run it the java command
 
Old 06-13-2011, 11:55 PM   #10
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,825

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
then put the path system wide
the file".bash_profile"is only read when YOU open a terminal

add it to /etc/bashrc - or - /etc/bashrc.local
that is where i normally set :
PATH ,PKG_CONFIG_PATH,LD_LIBRARY_PATH

when it is not 100% one user specific
 
Old 06-14-2011, 12:16 AM   #11
bigmac15
LQ Newbie
 
Registered: Jun 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Added it to .bashrc, logged off logged back on and same thing again.
 
Old 06-14-2011, 12:30 AM   #12
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
As one of the Users suggested putting the data directory to .bash_profile or any other profile won't help here as per my understanding.

java applications.TestMyDataReader < MyDataReader1.txt

This clearly mentions that you are reading something from a file from the current directory.

What best you can do is to modify the program to automatically pick the file from the data directory.

So run only java applications.TestMyDataReader.

or "java applications.TestMyDataReader MyDataReader1.txt" -- in this way you are accepting the file name as a parameter. Then look for the file name under the data directory and open it and process it.
 
Old 06-14-2011, 07:39 AM   #13
flakblas
Member
 
Registered: Jun 2009
Location: Maryland
Distribution: Fedora, CentOS, RHEL, Ubuntu
Posts: 41

Rep: Reputation: 3
Exactly. You're explicitly directing the input with the "< MyDataReader1.txt" part so your program can't override that. The only thing you could do is have your program ignore that input on STDIN and just use the data/MyDataReader1.txt path hard-coded in. It's dirty but that's the only way to bypass that explicit redirection that I can think of.
 
Old 06-14-2011, 08:39 AM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
How about putting a symlink in the base directory called "MyDataReader1.txt" that points to "data/MyDataReader1.txt"?

Like this (run in the base directory):

Code:
$ ln -s data/MyDataReader.txt MyDataReader.txt
 
Old 06-14-2011, 10:43 AM   #15
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
Technically Yes.. It will work. But everytime the user should create a symlink to the file if the file name is changing..
If the file name is not changing, why don't the program directly process the file, instead of accepting it as an input or getting the contents from it using a redirection. ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a .txt file in a specified directory.... msr4 Linux - Newbie 16 04-26-2011 03:02 PM
compare directory to .txt or .xml??? aircftech Programming 9 12-15-2010 01:14 PM
[SOLVED] How upload a txt file to a domain's base directory? JuJamEI Linux - Newbie 1 11-16-2010 01:17 PM
How do you add a .txt file to a domains base directory Trebore General 2 10-14-2009 03:47 PM
Bash, how do I test for *.txt files in a directory with IF? severian23 Programming 7 11-04-2004 10:47 AM


All times are GMT -5. The time now is 08:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration