I know the commands to get the browser version of Edge, Firefox and Chrome in mac using command line which is working properly on my system.
Edge=/Applications/"Microsoft Edge.app"/Contents/MacOS/"Microsoft Edge" -version
FireFox=/Applications/Firefox.app/Contents/MacOS/firefox -v
Chrome=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
Chrome1=/Applications/"Google Chrome.app"/Contents/MacOS/"Google Chrome" --version
When I try with Firefox it successfully returns me the Firefox version.
but when I try for the Edge or the chrome it throws error in the java program.
Cannot run program "/Application/"Google" error=2 no such file or directory
I tried the escaping the query as /Applications/\"Microsoft Edge.app\"/Contents/MacOS/\"Microsoft Edge\" -version.I am printing the same before passing as a query and I am exactly getting the same query which works if I directly copy paste it on the terminal.
below is the code snippet
Am I missing something?
String line;
Process process;
String msEdgeVersion = null;
/*process = Runtime.getRuntime().exec("/Applications/Firefox.app/Contents/MacOS/firefox -v");*/
process = Runtime.getRuntime().exec(/Applications/"Microsoft Edge.app"/Contents/MacOS/"Microsoft Edge" -version);
// process = Runtime.getRuntime().exec("where notepad");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = br.readLine()) != null) {
if (!StringUtils.isBlank(line)) {
msEdgeVersion = line;
System.out.println(line);
}
}
process.waitFor();
process.destroy();
According to the related api Runtime.getRuntime().exec(String command), you need to know that the parameter passed in is a valid String, so you need to pay attention to the format of the String parameter type.
Edit:
I reproduced your problem and got the same problem. After searching, I found the same problem. This is because the Process is different from the terminal process. You have to add -l to run the command as logged in user.
This is my test:
Related
I am facing issue while running this script(time.jsx):
var timeStr = system.callSystem("cmd.exe /c \"time /t\"");
alert("Current time is " + timeStr); Documentation of AE
it works in Adobe After Effects but I want to use it specifically in illustrator. Basically, i want to run my Python script from Extendscript(.jsx). But I couldn't find any solution to do so yet.
Your help is appreciated.
Thanks in Advance.
i have found a way to execute Python or other scripts in Extendscripts(*.jsx), and that is it, there is named File object in documentation which has a function named execute(); which executes the scripts according to their statement. For example, you want to execute hello world in python through .jsx file, you need to make a py file including print("hello world"). After that, add these lines in the script.jsx script:
var pyHello = new File("<path of py file>");
var bool = pyHello.execute();
alert(bool);
If script executed, it would be true, otherwise, false,
my Evironment is Windows10 64bit ,VS2015 ,GhostScript9.27,
Language is C#
And i using GhostScript.net to invoke GhostScript
here is my code
string inputFile = "D:\\112.pdf";
string outputFile = "D:\\output.pdf";
GhostscriptProcessor ghostscript = new GhostscriptProcessor();
List<string> switches = new List<string>();
switches.Add("-o");
switches.Add(outputFile);
switches.Add("-dNoOutputFonts");
switches.Add("-sDEVICE=pdfwrite");
switches.Add(inputFile);
ghostscript.Process(switches.ToArray());
and i try the script by the windows CMD Window
"gswin64.exe -o D:\output.pdf -dNoOutputFonts -sDEVICE=pdfwrite D:\112.pdf"
it works,
but when i run it in C# by GhostScript.net , it always give error
"An error occured when call to 'gsapi_init_with_args' is made: -100"
did anybody knows? thanks a lot for your help
The idea of the following was to use Bash's select from Python, e.g. use Bash select to get the input from the user, communicate with the Bash script to get the user selections and use it afterwords in the Python code. Please tell me if it at least possible.
Have the following simple Bash script:
#!/bin/bash -x
function select_target {
target_list=("Target1" "Target2" "Target3")
PS3="Select Target: "
select target in "${target_list[#]}"; do
break
done
echo $target
}
select_target
it works standalone
Now I tried to call it from Python like this:
import tempfile
import subprocess
select_target_sh_func = """
#!/bin/bash
function select_target {
target_list=(%s)
PS3="Select Target: "
select target in "${target_list[#]}"; do
break
done
echo $target
}
select_target
"""
target_list = ["Target1", "Target2", "Target3"]
with tempfile.NamedTemporaryFile() as temp:
temp.write(select_target_sh_func % ' '.join(map(lambda s : '\"%s\"' % str(s),target_list)))
subprocess.call(['chmod', '0777', temp.name])
sh_proc = subprocess.Popen(["bash", temp.name], stdout=subprocess.PIPE)
(output, err) = sh_proc.communicate()
exit_code = sh_proc.wait()
print output
It does nothing. No output, no selection.
I'm using High Sierra MacOS, PyCharm and Python 2.7.
PS
After some reading and experimenting ended up with the following:
with tempfile.NamedTemporaryFile() as temp:
temp.write(select_target_sh_func % ' '.join(map(lambda s : '\"%s\"' % str(s),target_list)))
temp.flush()
# bash: /var/folders/jm/4j4mq_w52bx2l5qwg4gt44580000gn/T/tmp00laDV: Permission denied
subprocess.call(['chmod', '0500', temp.name])
sh_proc = subprocess.Popen(["bash", "-c", temp.name], stdout=subprocess.PIPE)
(output, err) = sh_proc.communicate()
exit_code = sh_proc.wait()
print output
It behaves as I expected it would, the user is able to select the 'target' by just typing the number. My mistake was that I forgot to flush.
PPS
The solution works for MacOS X High Sierra, sadly it does not for Debian Jessie complaining the following:
bash: /tmp/tmpdTv4hp: Text file busy
I believe it is because `with tempfile.NamedTemporaryFile' keeps the temp file open and this somehow prevents Bash from working with it. This renders the whole idea useless.
Python is sitting between your terminal or console and the (noninteractive!) Bash process you are starting. Furthermore, you are failing to direct the standard output pipe anywhere, so subprocess.communicate() actually cannot capture standard error (and if it could, you would not be able to see the script's menu).
Running an interactive process programmatically is a nontrivial scenario; you'll want to look at pexpect or just implement your own select command in Python - I suspect this is going to turn out to be the easiest solution (trivially so if you can find an existing library).
In my program i need to run exe file in process. I'm doing it with ProcessBuilder. When i'm putting to code only directory and exe name, process is running normally, but i want to put arguments. When i'm trying it i'm getting exception with Acces Denied message.
It's my code:
Process process = new ProcessBuilder("C:\\Directory", "file.exe", argument1).start();
What is wrong with it?
My earlier code, that worked but without arguments was:
String folder = "C:\\Directory";
String exe = "File.exe";
ProcessBuilder pb = new ProcessBuilder();
pb.command(folder + exe);
pb.start();
With this code i was able to see started process in ProcessManager.
Your code is trying to execute C:\\Directory which is not allowed.
The full path of the executable must be in the first argument to the constructor, so:
Process process = new ProcessBuilder("C:\\Directory\\file.exe", argument1).start();
This is assuming C:\Directory\file.exe is the program you are trying to run.
Update: In your original code you have:
String folder = "C:\\Directory";
String exe = "File.exe";
so 'folder + exe' is C:\DirectoryFile.exe so you the equivalent code is:
Process process = new ProcessBuilder("C:\\DirectoryFile.exe", argument1).start();
I read this website : http://lenskit.org/documentation/evaluator/quickstart/ I first tried to run it using the script " $ lenskit eval " and I just created a new groovy file in my hello-lenskit example and run it using the command line but nothing happened. Then I tried to use it in Java program(hello-lenskit.java).
I run into some errors.
File dataFile = new File("ml-100k/u.data");
PreferenceDomain domain = new PreferenceDomain(1.0,5.0,1.0);
DataSource data = new CSVDataSource("ml-100k",dataFile,"\t",domain);//give me an error CSVDataSource is not public and can not be accessed from the outside package.
CrossfoldTask cross = new CrossfoldTask();
LenskitConfiguration config1 = new LenskitConfiguration();
config1.bind(ItemScorer.class)
.to(UserMeanItemScorer.class);
AlgorithmInstance alg1 = new AlgorithmInstance("PersMean",config1);
evl.addAlgorithm(alg1);
LenskitConfiguration config2 = new LenskitConfiguration();
config2.bind(ItemScorer.class)
.to(ItemItemScorer.class);
config2.bind(UserVectorNormalizer.class)
.to(BaselineSubtractingUserVectorNormalizer.class);
config2.within(UserVectorNormalizer.class)
.bind(BaselineScorer.class,ItemScorer.class)
.to(ItemMeanRatingItemScorer.class);
AlgorithmInstance alg2 = new AlgorithmInstance("ItemItem",config2);
evl.addAlgorithm(alg2);
evl.addMetric(RMSEPredictMetric.class);
File file = new File("eval-results.csv");
evl.setOutput(file);
What should I do next? How could I generate the overall rating error?
Using the LensKit evaluation commands manually is difficult, undocumented, and not recommended.
The SimpleEvaluator is the best way to get overall accuracy from a LensKit recommender in a Java application.
For further assistance in debugging LensKit runs, I recommend e-mailing the mailing list with exactly the commands you are running and the output or errors you are getting.