LinuxQuestions.org
Review your favorite Linux distribution.
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 04-18-2018, 02:37 PM   #1
Stavsen
LQ Newbie
 
Registered: Apr 2018
Posts: 1

Rep: Reputation: Disabled
How to run an exe in another dir


Hi
Im trying to run an exe in another directory like this:
Code:
./bin/a.out
but when i do it says
Code:
not found
but when i go to bin first and then run the exe it works?
Code:
cd bin
./a.out
whats going wrong?

Last edited by Stavsen; 04-18-2018 at 02:40 PM.
 
Old 04-18-2018, 02:58 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,138

Rep: Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343Reputation: 5343
Welcome to LinuxQuestions.

The . in your command ./a.out is a shortcut for current working directory i.e. the directory the terminal is at the time you run the command. Most linux distributions do no include the current working directory in the path environment for security reasons which is why when you run the command you need to add ./

If you want to run the command from another directory that is not in your path environment you use the complete path i.e. /bin/a.out

Many distributions include /bin in a users path environment and therefore to run the command you just type in a.out. Although a.out is the default compiler program name and if you have more then one scattered throughout you may not execute the intended program.
 
Old 04-18-2018, 07:52 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 18,656
Blog Entries: 28

Rep: Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902Reputation: 5902
Can you run the program when you call it by the complete /path/to/program?

Last edited by frankbell; 04-18-2018 at 08:16 PM.
 
Old 04-18-2018, 08:02 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,113

Rep: Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159
...NM...
 
Old 04-19-2018, 04:54 AM   #5
fatmac
Senior Member
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan with some Tiny Core, Fatdog, Haiku, & BSD thrown in.
Posts: 4,922

Rep: Reputation: Disabled
You don't have ./bin in your PATH statement.
Either add it, or use a full path to the file.

Last edited by fatmac; 04-19-2018 at 04:56 AM.
 
Old 04-19-2018, 06:24 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,167

Rep: Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680Reputation: 2680
You can always run a prog (if it has x perms & correct ownerships) via relative or absolute paths, without having the dir in your PATH
Code:
pwd
/home/chris

./dev/t.sh
unset etc

/home/chris/dev/t.sh
unset etc

echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
NB: of course for shell scripts & similar it also needs 'r' perm.
 
Old 04-19-2018, 06:34 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,642

Rep: Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551Reputation: 3551
It's the point/dot/period.
 
Old 04-20-2018, 12:10 AM   #8
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,521

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
You want
Code:
$ bin/./a.out
 
  


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
[SOLVED] equivalent in linux for the dos command dir *.exe /s Qyko Linux - Newbie 2 04-05-2015 10:53 AM
copying files from home dir to another dir from another dir in a lower dir chomito44 Linux - General 5 10-19-2013 06:18 PM
samba compatibility with microsoft srvtools.exe (usrmgr.exe and srvmgr.exe) checkmate3001 Linux - Software 1 09-06-2008 05:08 AM
how to run .exe file as we run the samwe in windows chandrala13 Linux - Newbie 2 05-22-2008 05:30 AM
SETUP.EXE/autorun.exe don't run in wine mst3kman Linux - Games 3 01-22-2006 02:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:28 PM.

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
Open Source Consulting | Domain Registration