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)
Related
I'm trying to execute sh-file from resources.
Executed file is located at the root of resources: src/main/resources/hiveCommand.sh
import sys.process._
"./hiveCommand.sh" !!
But receive IOException: not such file or directory
What am I doing wrong?
Scala's Process integration does not know how to handle shell scripts. It can only start programs. To run a shell script you need start a shell (e.g. bash) and give it the file to run as an argument.
There is a complication however. Since the script is a resource (located at src/main/resources/hiveCommand.sh during compile time), it is located in a jar at run time.
So in short:
First extract the shell script (use getClass.getResourceAsStream("/hiveCommand.sh") to read the resource) and store it on disk.
Then start with something like:
"bash /tmp/hiveCommand.sh".!!
I'm trying to use the input function from the Sys class, but when I run the build and the prompt occurs, I'm unable to enter any input. What alternatives are there to Sys, or what ought I do to resolve this? I've checked Haxelib and haven't found anything that I think can be used.
For reference, what I have written:
Sys.println("First player's name: ");
var p1:String = Sys.stdin().readLine();
My hxml args:
-main Main.hx
-cp src
-cp src/cards
-cp src/cards/library
-lib Random
-neko test.n
-cmd neko test.n
It works fine if you manually start the generated test.n instead of doing that via -cmd in the hxml. I suspect that the Haxe process does not direct input to the stdin of the -cmd process or something like that.
If you still want to compile and run at the same time, I recommend creating a little .bat (or .sh if you're on Linux) script for this:
haxe build.hxml
neko test.n
I'm launching a perl build script with a .vbs file, however when the perl window is executed it gives me "Can't find cl.exe, no such file or directory"
Running the perl script directly gives no errors. Visual studio bin folder is in my path
Any suggestions? Build script is a standard perl invoking multiple programs, .vbs script below
Dim ss
Set ss = CreateObject("WScript.Shell")
ss.CurrentDirectory = "MyBuildDirectory"
ss.run build.pl, 1, True
Look here.
Did you notice that the first argument is given as strCommand? That means it's a string. What's an unquoted build.pl?
I'm not sure why it gives you the error it does, but I know that it's probably looking for an object named 'build' and trying to get the property named 'pl'.
Pure Voodoo, but try
iRet = ss.Run("%comspec% /c ""f:\ullpathto\perl.exe"" ""f:\ullpathto\build.pl""", 1, True)
If it 'works' you can delete redundant parts/pathes.
(I believe that the error message proves that the process started by .Run does not have the path to cl.exe)
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'm developing a Nagios plugin in Perl (no Nagios::Plugin, just plain Perl). The error condition I'm checking for normally comes from a command output, called inside the plugin. However, it would be very inconvenient to create the error condition, so I'm looking for a way to feed test output to the plugin to see if it works correctly.
The easiest way I found at the moment would be with a command line option to optionally read input from a file instead of calling the command.
if($opt_f) {
open(FILE, $opt_f);
#output = <FILE>;
close FILE;
}
else {
#output = `my_command`;
}
Are there other, better ways to do this?
Build a command line switch into your plugin, and if you set -t on the command line, you use your test command at /path/to/test/command, else you run the 'production' command at /path/to/production/command
The default action is production, only test it the switch indicating test mode is present.
Or you could have a test version of the command that returns various status for you to test (via a command line argument perhaps).
You put the test version of mycommnd in some test directory (/my/nagois/tests/bin).
Then you manipulate the PATH environment variable on the command line that runs the test.
$ env PATH=/my/nagois/tests/bin:$PATH nagios_pugin.pl
The change to $PATH will only last for as long as that one command executes. The change is localized to the subshell that is spawned to run the plugin.
The backticks used to execute the command will cause the shell to use the PATH to locate the command, and that will the the test version of the command, which lives in the directory that is now the first one on the search path.
let me know if I wasn't clear.
New answer for new method.