windows command config file? - windows

I'm running a few different windows command scripts that all reference the same directory. The directory I want to reference changes from day to day depending on what I'm working on. I've looked into taking command line args, but I think the more elegant solution would be to have all the scripts reference some sort of config file, if such a thing is possible. Then I could change the directory address one place to change all of my standard command scripts. If it's not abundantly clear, I'm new to windows scripting.
Q: Is there a way to retrieve data from an external config in a windows command script?
PS - Don't be limited by my question, if you think you have a better solution for what I'm trying to do, I'm all ears.

The simplest thing would be to use an environment variable.
eg:
set my_path=c:\foo\bar
then in the script you can use %my_path% and it will be expanded for you.

Related

Is it possible to setup 2 different AIRFLOW_HOME path on the same server in bash_profile

I need to setup these two paths in my bash_profile
export AIRFLOW_HOME=pwd/airflow
and
export AIRFLOW_HOME=pwd/airflow_2
for the same server so that two different versions of airflow can coexist. Is this possible?
Can't think of any solution.. any suggestions will of great help.
Every environment variable must, by definition, be unique and non-ambiguous.
Either the software itself, or the script wrapping the software, could work with another environment variable (i.e. AIRFLOW_HOME_OPTS) which could be assigned the following value
AIRFLOW_HOME_OPTS="pwd/airflow:pwd/airflow_2"
which the wrapper could then parse depending on command line options, i.e. --default/--v2 .
Assuming this is an installation dedicated to a single user, you could also have the libraries installed in each of
pwd/airflow_1
pwd/airflow_2
and, again via wrapper option, create a symlink on the fly to whichever is the one you wish to use at the time the command executes, and removes that when the program ends.

Trying to Set a Shortcut to a Directory

Im trying to run several different scripts on my Mac for data stored in different paths. So I put all said scripts into a folder. In order for a script to work, I have to be cd'd to a specific folder required for said script. I use the scripts to get different types of output (ex: Image volumes, MRI info, etc..).
I was wondering if there was a way to store all my scripts in one directory and assign a shortcut to it. That way, I can cd to my folder, and only type something like $ScriptsFolder/Script_1 to have it. Ive seen this done in the FSL software package, where typing $FSLDIR/data/standard would give you the items in that folder.
UPDATE:
Im using Script=/Users/ray/Documents/Script which works until I close down my terminal to start a new one. Any way to make the setup permanent?
EDITED
Found this helpful in the end.
http://www.techradar.com/how-to/computing/apple/terminal-101-creating-aliases-for-commands-1305638
I used it to create a shortcut to my scripts which are all placed in a folder for easy referencing.

Why does Powershell search every directory within one's $PATH for a PSConsoleHostReadLine file?

all!
I noticed that Powershell, or more specifically, pasting and tab-completing within Powershell, was a lot slower on my machine after upgrading to v3 from v2. I opened up procmon to see what was going on, only to find out that every attempt to tab-complete or paste anything triggers Powershell to find various permutations of the file provided in the subject. I have some network folders in my $PATH and walking through those folders every time I paste something seems non-ideal.
It seems that this file allows Powershell to behave more like Bash. While this is absolutely FANTASTIC and I'm looking forward to abusing this feature in the very near future, is there any way to configure Powershell such that it only attempts to find this file in one directory?
Thanks!
PSConsoleHostReadLine is actually a function. If PoSH can't find a method, alias, or anything else executable with that name, it falls back to it's default 'cooked' readline with editing, etc.
To redefine it, create a function:
function PSConsoleHostReadline {
[Console]::Readline()
}
As written, this method disables editing, etc. Write your own insane magic to do whatever you wish.
I'm guessing it's searching all the extra locations due to Powershell 3 having "Module Auto Load" which checks for a function in all locations known in the ENV:PSModulePath, and auto-loads the module which contains said method.
This was an oversight in V3. V4 will only search for functions or aliases - it won't search for external exes when looking for PSConsoleHostReadline.
If you're looking for a bash like experience - check out https://github.com/lzybkr/PSReadLine

How to zip a file in windows shell without vb script and with Window default zip only

Is their a way to zip a file without VB Script.I got a lot of examples on web to zip file or folder using vbs but i want to do it in a single BAT file.
Yes and no. There is no built in way to do this inside windows. You can use a external application like vbscript, a exe file like 7zip, rar, lots of resources can do this. Since windows is application poor when it comes to command lines is not really surprising. But no you do not need the VB Script for anything.
Just not so easy out of the box. Maybe makecab could do it for you? As a general rule you have a hard constraint in your question. A single BAT file which in general can not do almost anything without the support of hundreds of preinstalled or commonly installed other applications.
Could you specify a the constraints a bit better. Tel WHY you need this particular constraint? And what does it mean as even most of the bat command you use require more than one file.

Can XSLT execute a shell script at the OS level?

I have a production flow that combines XSLT and some shell scripts in about 4 steps before it reaches completion. I execute each step manually at the moment.
I'm using Saxon 9 from the command line in Linux. Can I have the xsl's execute shell scripts.. instead of me?
(I know I could achieve the desired result in another way with Ant or Make.. but prefer to stay in XSLT if it is not a huge effort to do so)
Update: I've minimized my shell scripts and sped things up using Xproc. I'm not entirely satisfied with the result, but Xproc has improved life. Kai's suggestion below looks good.. but I have not tried it yet.
I'm not Java savvy either, but I found with Michael Kay's tutorials on the Saxonica website it's doable.
Here's what I did and what's working well for me:
In the root element of the XSLT stylesheet I assigned a namespace for the function (in my case I'm using it for unzipping, so I named the prefix unzip, but that could certainly be anything):
xmlns:unzip="java:java.lang.Runtime"
I am defining a variable with a file path for a batch file to be called later. Then I am using
<xsl:result-document href="{$batchFile}" method="text"> ... </result document>
to create the batch file. (Unzipping could be certainly done with just a command, but I found the batch file version more handy as I needed to combine the unzip-command with some change directory command and other little stuff. And furthermore using a batch file opens up a world of more elaborate tasks that could be called from the XSLT sheet.)
When I need my batch file be executed, I insert an xsl:message like this:
<xsl:message>Executing <xsl:value-of select="unzip:exec(unzip:getRuntime(),concat('cmd /c /y start ',$batchFile))"/></xsl:message>
Hope that helps,
best regards,
Kai
You can call java.lang.Runtime.exec() in the same way as any other external Java function.

Resources