Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to run a windows batch file from a ssh login. I have successfully installed cygwin w/ OpenSSH on the server (windows 2003).

I can log in and run the file, but the file does not run properly because it relies on an environment variable. I discovered that for security reasons not all environment variables are added to the ssh shell. I added the environment variable I need (in ~/.profile), but the file still errors out.
I modified the file and had it output the environment variable that was causing issues before, and I discovered that it was still not set. So, even though I added the environment variable, and it exists in the shell, it is not available in the shell the batch file is being run in.

How would I add the environment variable to the batch file's shell?
Modifying the file permanently is not an option; it is created by another program, and I am trying to write a git hook to run the file on another machine after a "git push"

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You could write a small shell script that sets the environment variable(s) and then runs the batch file. For example:

#!/bin/bash
export VAR1="value of VAR1"
export VAR2="value of VAR2"
./script.bat

This example assumes that script.bat is in the current working directory and that you have execute permission for it.

share|improve this answer
    
that's what I ended up doing. the problem is that the script is in a folder that the build process of the program recreates, so it would get overwritten. It has to be called from that directory too, as it relies on the pwd variable. I worked around the issue though by creating the file on the fly as I needed it with echo commands. –  AsherMaximum Jun 11 '12 at 11:21
    
You could put the above shell script in a place where it can persist, then put a cd ... command just before the ./script.bat to change to the appropriate directory just before launching the batch file. That way the above shell script doesn't have to be overwritten or deleted. –  Fran Jun 11 '12 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.