Can any one explain the usage of Shell::Source perl module or Shell::GetEnv module - linux

I m a beginner in perl. I want to know how to use this module. I read somewhere about this module but not getting its usage.
Actually I've a file which contains some environment paths which needs to be set while running some test(say file name is SET_ENV_TOOL1.csh or SET_ENV_TOOL1.sh) with particular tools.(say TOOL1, TOOL2 etc)
SET_ENV_TOOL1.sh file conatins:
setenv UVM_HOME /u/tools/digital/uvm/uvm-1.1a
setenv VIPP_HOME /u/tools/digital/vipcat_11.30-s012-22-05-2012
setenv VIP_AXI_PATH ${VIPP_HOME}/vips/amba_axi/vr_axi/sv/ #etc.(almost 10-15 paths are need to be set like this)
Everytime while running test, tool might get changed and so environment paths also needs to set to run that tool.
I have to make a perl script which sets these paths before running test. That test will run a command and that command will use these environment paths.
Any help would be greatly appreciated. Thanks !!

Reading and changing environment variables is built-in to Perl, you do not need the modules you mentioned.
$ENV{UVM_HOME} = '/u/tools/digital/uvm/uvm-1.1a';
$ENV{VIPP_HOME} = '/u/tools/digital/vipcat_11.30-s012-22-05-2012';
$ENV{VIP_AXI_PATH} = "$ENV{VIPP_HOME}/vips/amba_axi/vr_axi/sv/";

Related

Tesseract not using path variable

Why does my Tesseract instance require me to explicitly set my datapath, but doesn't want to read the environment variable?
Let me clarify: running the code
ITesseract tesseract = new Tesseract();
String result = tesseract.doOCR(myImage);
Throws an error:
Error opening data file ./tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to the
parent directory of your "tessdata" directory.
I already have set my environment variable, ie doing
echo $TESSDATA_PREFIX returns /usr/share/tessdata/
Now, setting the path variable explicitly in my code, ie:
Itesseract tesseract = new Tesseract();
tesseract.setDatapath("/usr/share/tessdata/");
String result = tesseract.doOCR(myImage);
WORKS PERFECTLY. Why?
I'm using Manjaro 17.0.5
The library was initially designed to use the data files bundled in its tessdata folder. In your case, if you want to read from the standard tessdata directory, you would want to set datapath as follows:
tesseract.setDatapath(System.getenv("TESSDATA_PREFIX"));

Win10: ASDF can't load system (ASDF_OUTPUT_TRANSLATION error)

Update 2
I think #faré is right, it's an output translation problem.
So I declared the evironment variable ASDF_OUTPUT_TRANSLATIONS and set it to E:/. Now (asdf:require-system "my-system") yields a different error: Uneven number of components in source to destination mapping: "E:/" which led me to this SO-topic.
Unfortunately, his solution doesn't work for me. So I tried the other answer and set ASDF_OUTPUT_TRANSLATIONS to (:output-translations (t "E:/")). Now I get yet another error:
Invalid source registry (:OUTPUT-TRANSLATIONS (T "E:/")).
One and only one of
:INHERIT-CONFIGURATION or
:IGNORE-INHERITED-CONFIGURATION
is required.
(will be skipped)
Original Posting
I have a simple system definition but can't get ASDF to load it.
(asdf-version 3.1.5, sbcl 1.3.12 (upgraded to 1.3.18 AMD64), slime 2.19, Windows 10)
What I have tried so far
Following the ASDF manual: "4.1 Configuring ASDF to find your systems"
There it says:
For Windows users, and starting with ASDF 3.1.5, start from your
%LOCALAPPDATA%, which is usually ~/AppData/Local/ (but you can ask in
a CMD.EXE terminal echo %LOCALAPPDATA% to make sure) and underneath
create a subpath config/common-lisp/source-registry.conf.d/
That's exactly what I did:
Echoing %LOCALAPPDATA% which evaluates to C:\Users\my-username\AppData\Local
Underneath I created the subfolders config\common-lisp\source-registry.conf.d\ (In total: C:\Users\my-username\AppData\Local\config\common-lisp\source-registry.conf.d\
The manual continues:
there create a file with any name of your choice but with the type conf, for instance 50-luser-lisp.conf; in this file, add the following line to tell ASDF to recursively scan all the subdirectories under /home/luser/lisp/ for .asd files: (:tree "/home/luser/lisp/")
That’s enough. You may replace /home/luser/lisp/ by wherever you want to install your source code.
In the source-registry.conf.d folder I created the file my.conf and put in it (:tree "C:/Users/my-username/my-systems/"). This folder contains a my-system.asd.
And here comes the weird part:
If I now type (asdf:require-system "my-system") in the REPL I get the following error:
Can't create directory C:\Users\my-username\AppData\Local\common-lisp\sbcl-1.3.12-win-x86\C\Users\my-username\my-systems\C:\
So the problem is not that ASDF doesn't find the file, it does -- but (whatever the reason) it tries to create a really weird subfolder hierarchy which ultimately fails because at the end it tries to create the folder C: but Windows doesn't allow foldernames containing a colon.
Another approach: (push path asdf:*central-registry*)
If I try
> (push #P"C:/Users/my-username/my-systems/" asdf:*central-registry*)
(#P"C:/Users/my-username/my-systems/"
#P"C:/Users/my-username/AppData/Roaming/quicklisp/quicklisp/")
> (asdf:require-system "my-system")
I get the exact same error.
I don't know what to do.
Update
Because of the nature of the weird path ASDF was trying to create I thought maybe I could bypass the problem by specifying a relative path instead of an absolute one.
So I tried
  (:tree "\\Users\\my-username\\my-systems")
in my conf file. Still the same error.
Ahem. It looks like an output-translations problem.
I don't have a Windows machine right now, but this all used to work last time I tried.
Can you setup some ad hoc output-translations for now that will make it work?

Node.js / Export configuration file

I have the following configuration file in /etc/sysconfig/myconf:
export USER=root
export NODE_DIR=/opt/MyDir
I want to use these setting in my .js file, which located in /opt/myapplication:
var userApp = //USER in /etc/sysconfig/myconf file
var dir = //NODE_DIR in /etc/sysconfig/myconf file
Is there any way to do it without open the file and parse it contents?
As I understand the export should give me the option to read it easily in node.js, but I don't find how (In addition, when I run export -p, I don't see these variables)
EDIT: what I search is equal Node.js's command to source command in Linux (the variables is not environment variables)
If those environment variables are available when you launch the program, you can use process.env. https://nodejs.org/api/process.html#process_process_env

environment variable in a config.properties file

I'm trying to compile a Maven project that has a config.properties file. In the file, I have a set of environment variables that I have to set before compile.
In the config.properties file the variables are called like this:
${sys:rdfstore.host}:${sys:rdfstore.port}/openrdf-sesame/repositories/iserve/rdf-graphs/service
How do I have to set the variable rdfstore.host, and to what value should I set it to?
I have tried to solve this with:
export rdfstore.host="localhost"
However, with this I obtain a msj that is a invalid identifier, because
it has a point "." How can I solve this problem?
You should be confusing environment variables and the set of sytem properties:
The properties exported from your system as you did with the export command are called environment variables and should not contain dots in the name.
Those properties are then refered to using ${env.XXX}, meaning in your case you should change the variable name to:
export RDFSTORE_HOST="localhost"
It can then be referred to as below:
`${env.RDFSTORE_HOST}`
System variables are those introcued in command line when invoking a maven phase, those ones can host dots in their names:
mvn -Drdfstore.host="localhost"
They can be referred to as follows:
${rdfstore.host}
You can find more informations in the maven properties manual.

How do you get the path of the running script in groovy?

I'm writing a groovy script that I want to be controlled via a properties file stored in the same folder. However, I want to be able to call this script from anywhere. When I run the script it always looks for the properties file based on where it is run from, not where the script is.
How can I access the path of the script file from within the script?
You are correct that new File(".").getCanonicalPath() does not work. That returns the working directory.
To get the script directory
scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
To get the script file path
scriptFile = getClass().protectionDomain.codeSource.location.path
As of Groovy 2.3.0 the #SourceURI annotation can be used to populate a variable with the URI of the script's location. This URI can then be used to get the path to the script:
import groovy.transform.SourceURI
import java.nio.file.Path
import java.nio.file.Paths
#SourceURI
URI sourceUri
Path scriptLocation = Paths.get(sourceUri)
Note that this will only work if the URI is a file: URI (or another URI scheme type with an installed FileSystemProvider), otherwise a FileSystemNotFoundException will be thrown by the Paths.get(URI) call. In particular, certain Groovy runtimes such as groovyshell and nextflow return a data: URI, which will not typically match an installed FileSystemProvider.
This makes sense if you are running the Groovy code as a script, otherwise the whole idea gets a little confusing, IMO. The workaround is here: https://issues.apache.org/jira/browse/GROOVY-1642
Basically this involves changing startGroovy.sh to pass in the location of the Groovy script as an environment variable.
As long as this information is not provided directly by Groovy, it's possible to modify the groovy.(sh|bat) starter script to make this property available as system property:
For unix boxes just change $GROOVY_HOME/bin/groovy (the sh script) to do
export JAVA_OPTS="$JAVA_OPTS -Dscript.name=$0"
before calling startGroovy
For Windows:
In startGroovy.bat add the following 2 lines right after the line with
the :init label (just before the parameter slurping starts):
#rem get name of script to launch with full path
set GROOVY_SCRIPT_NAME=%~f1
A bit further down in the batch file after the line that says "set
JAVA_OPTS=%JAVA_OPTS% -Dgroovy.starter.conf="%STARTER_CONF%" add the
line
set JAVA_OPTS=%JAVA_OPTS% -Dscript.name="%GROOVY_SCRIPT_NAME%"
For gradle user
I have same issue when I'm starting to work with gradle. I want to compile my thrift by remote thrift compiler (custom by my company).
Below is how I solved my issue:
task compileThrift {
doLast {
def projectLocation = projectDir.getAbsolutePath(); // HERE is what you've been looking for.
ssh.run {
session(remotes.compilerServer) {
// Delete existing thrift file.
cleanGeneratedFiles()
new File("$projectLocation/thrift/").eachFile() { f ->
def fileName=f.getName()
if(f.absolutePath.endsWith(".thrift")){
put from: f, into: "$compilerLocation/$fileName"
}
}
execute "mkdir -p $compilerLocation/gen-java"
def compileResult = execute "bash $compilerLocation/genjar $serviceName", logging: 'stdout', pty: true
assert compileResult.contains('SUCCESSFUL')
get from: "$compilerLocation/$serviceName" + '.jar', into: "$projectLocation/libs/"
}
}
}
}
One more solution. It works perfect even you run the script using GrovyConsole
File getScriptFile(){
new File(this.class.classLoader.getResourceLoader().loadGroovySource(this.class.name).toURI())
}
println getScriptFile()
workaround: for us it was running in an ANT environment and storing some location parent (knowing the subpath) in the Java environment properties (System.setProperty( "dirAncestor", "/foo" )) we could access the dir ancestor via Groovy's properties.get('dirAncestor').
maybe this will help for some scenarios mentioned here.

Resources