I am trying to run Scala in TextMate. I have created a new variable TM_SCALA and set it to the path which I obtained on executing the following command on the terminal
which scala
But when I try to run a Scala program, I get the error
Run Script: line 4: scala: command not found
This is the run script
#!/usr/bin/env bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
scala -classpath . -savecompiled "$TM_FILEPATH"
I am unable to understand the problem. Thanks in advance.
Make sure you have scala downloaded.
update PATH variable in TextMate preferences. Append scalac path there.
Add a new command (or replace the 'run script' one) with this:
#!/usr/bin/env ruby -w
cmd = ENV['SCALA_HOME'] + "/scala -nocompdaemon -howtorun:script '" + ENV['TM_FILEPATH'] + "'"
result = "" + `#{cmd}`
puts "#{result}"
That assumes that you have a SCALA_HOME environment variable set to something like this:
export SCALA_HOME="/path/to/my/scala/scala-2.11.4/"
Related
Is it possible to write a command inside sbt's shell using multiple lines?
For example, suppose I'm inside the sbt project for scalac itself:
$ git clone git#github.com:scala/scala.git
$ cd scala
$ sbt
> run file1.scala file2.scala file3.scala
Can I pass arguments to the run command on multiple lines? In bash, opening a single ' or a double quote ", or writing a \ at the end of a line allows command to spawn across multiple lines, is there an equivalent feature in sbt?
I have a set of json files in directory /Desktop/jsons, and I have a Scala script which takes in a json and outputs stuff. I can run it manually in the terminal by cding into the directory of the Scala script (/Me/dev/scalastuff) and running
sbt --error "run /Desktop/jsons/jsonExample.json",
which outputs the stuff I want in the terminal.
I want to write a Python script which does this automatically and additionally outputs a json file with the "stuff" thats outputted by the Scala script.
My issues right now are using subprocessing. When I try to run
BASEDIR = '/Me/dev/scalastuff'
p = subprocess.Popen(['sbt --error "run /Desktop/jsons/jsonExample.json"'], cwd = BASEDIR, stdout = subprocess.PIPE)
out = p.stdout.read()
print out
I get OSError: [Errno 2] No such file or directory.
I'm completely stumped as to why this is occurring. I'm new to subprocess, so be light on me!
popen in python takes a list of shell arguments. You're passing only one!
So it's trying to execute a file named wholly 'sbt --error "run /Me/Desktop/jsons/jsonExample.json"'.
Obviously, this doesn't work.
If you use popen; only pass a simple array -- you needn't care about escaping:
subprocess.popen(['sbt', '--error', 'run /Me/Desktop/...'], cwd = BASEDIR, stdout = subprocess.PIPE)
I'm trying to use a command that uses environment variables, and following is working fine( this is not the actual command I'm going to use).
Seq("echo "+System.getenv("JAVA_HOME"))!
but is there way to use the following kind of syntax ? In the case if we load the command from .sh file ?
Seq("echo ${JAVA_HOME}")!
You can use scala process with bash -c to get environment variables:
import scala.sys.process._
val value = Seq("bash", "-c", "echo $JAVA_HOME").lines.head
I am having trouble launching an executable that I have created from a shell script. I would like to automate testing by running the program many times with different command line options to verify it is working.
When I type echo $SHELL, /bin/sh is displayed.
The following is my shell script:
#!/bin/sh
clear
echo "Running first test."
./myProgram
exit 0
When I run the script (sh myScript.sh), with myProgram in the same directory, I see the following output:
Running first test.
: not foundsh: line 4:
When executing the program ./myProgram, it runs as expected with no command line options.
I have also tried:
myProgram
./myProgram &
myProgram &
based on answers to somewhat similar questions, but they all result in the above error message.
Your newlines are goofed. Use dos2unix to fix.
why don't you try using the full path?
e.g., if myProgram is in /home/user1/bin, you can try /home/user1/bin/myProgram instead of ./myProgram. This should work.
You can also add the path to path variable, $PATH and directly call myProgram from anywhere.
Run "export PATH=$PATH:/home/user1/bin" on your terminal without the quotes. Note that this affects only your current termial session. If you want to permanently add the path, update your .bashrc file in your home directory with the following line:
I am looking for a nice way to get the following done:
So I have a script that I need to run in Python in Unix by calling from a Perl script that was, in turn, called from my Excel VBA macro in Windows using Plink. The Python script, due to dependency issues, has to run in either csh or bash, and I will need to use export/setenv to add a few libraries before running the script. However by default, perl runs in sh shell and as such, there is no way I can add in all the dependencies and have the Python script to run.
So, I am just wondering if there is EITHER: 1. a way for me to add dependencies to sh shell in the perl script, OR 2. force my perl script to run in csh (preferred, since for some reason .bashrc for the account runs into permission issues).
Thanks a lot!
How about "3. Set the appropriate environment variable in the Perl or Python scripts"?
$ENV{'PATH'} = ...
...
os.environ['PATH'] = os.pathsep.join(newpaths + os.environ['PATH'].split(os.pathsep))
(dunno how to get the path separator in Perl, sorz)
To force the shell to csh, try the following in Perl :
`/bin/csh -c "command_name"`;
Edit:
You can use ENV variable, like this. Try that :
$s = `/bin/bash -c 'VAR_FOO=753; echo \$VAR_FOO'`;
print $s;
I ended up just change the .cshrc script, apparently the addition to PATH, for some reason, did not work for me. After that, everything runs smoothly by putting all into one line
so basically it looks something like this
/path/to/.cshrc && /python/path/to/python
Hope that helps!