简体   繁体   中英

Shell command executed from scala code not recognizing bash alias

I have a scala file that executes a hdfs command similar to this:

hdfs dfs -mkdir /test/

The command runs fine when I run it in my shell because I have the following alias set in my .bashrc file:

alias hdfs='/usr/local/hadoop-2.7.0/bin/hdfs'

...however when I build the code that runs the shell command in my Scala code using SBT I get the following error:

 java.io.IOException: Cannot run program "hdfs": error=2, No such file or directory

Is there a way for the alias to be recognized? I cannot change the code because I want the program to run on any system with hdfs installed, no matter the directory, the only thing that should change is the alias.

Futher information: I'm running my test in a docker image with hadoop (shouldn't change anything), the image runs a script that executes the following two lines every time the container starts up:

source ~/.bashrc         # To get the alias
shopt -s expand_aliases  # To allow alias expansion in your script

在我的.bashrc文件中的以下行已修复

export PATH=$PATH:/usr/local/hadoop/bin/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM