I wanted to start appium server programatically using java in Mac.
I am able to open terminal with following code:
String cmd= "osascript -e \"tell app \\\"Terminal\\\" to activate\"";
List<String> command1=new ArrayList<String>();
command1.add("/bin/sh");
command1.add("-c");
command1.add(cmd);
ProcessBuilder pb=new ProcessBuilder(command1);
pb.start();
But I am not able to send any command in terminal.
Please suggest any solution.
Thanks in advance. :)
It seems you are trying to open Terminal app, which is not required rather you can try this:
There are many ways to do start appium programatically:
1. Create a text file and write command: export PATH=$PATH:/usr/local/bin; /usr/local/bin/appium & -g /tmp/app.log --command-timeout 90 and save this file with .sh extension say test.sh and give executable permission to this file like chmod +x test.sh
2. Now you can execute this command using your java code like: Runtime.getRuntime().exec("<PATH_TO_FILE>/test.sh");
Thats all. You can check if appium is running by browsing localhost:4723,
if you are writing further tests, you need to wait until appium server is started in your code.
Related
I wrote a little java program and now I want to execute this .jar file from a .sh script.
my script:
#! /bin/bash
java -jar /var/spool/sms/sentSMS.jar
then i run the command: sudo bash sentSMS.sh
an get following error:
ERROR: Unable to access jarfile /var/spool/sms/sentSMS.jar
I am using a Raspberry with raspian-jessie, if this important to solve it.
Sorry, but I'm new in scripting with linux.
Take into account that the user must have at least READ permissions on that file.
Also, as you say you are new in linux, make sure the name is correct. sentSMS.jar is different from sentsms.jar
I am trying to automate android devices using appium in Mac machine(Yosemite OS).
I downloaded and set all the required PATHS like sdk,build-tools,tools,paltform-tools,platforms and able to run the adb commands through terminal sucessfully.
But I written sample below java code
**Process p = Runtime.getRuntime().exec("adb devices");**
Getting output:
Cannot run program "adb": error=2, No such file or directory**
I am unable to figure out the exact problem, why it is working through terminal and why i am getting error through eclipse even I set path for everything.
Could you please any one suggest me what exactly the issue.Please do the needful.
could you please try the following line:
Process p = Runtime.getRuntime().exec(new String[]{"bash", "-l", "-c", "adb devices"});
My answer is based on another link in stackoverflow which resolved my problem and it sounds very similar to yours:
https://stackoverflow.com/a/54923150/3439297
I faced this issue with IntelliJ community edition+ Mac combo. But the reason seems the same, try to invoke your IDE (Eclipse) using the command prompt (Via Terminal) so that it can use the system paths, and in turn recognize adb, you mentioned that adb works from terminal so once the IDE launches from terminal again the paths would be honored.
You can use following code on Android:
To enable the WIFI:
String ADB=System.getenv("ANDROID_HOME");
String cmd = "/platform-tools/adb shell am broadcast -a io.appium.settings.wifi --es setstatus enable";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(ADB+cmd);
pr.waitFor();
To Disable the WIFI use:
String ADB=System.getenv("ANDROID_HOME");
String cmd = "/platform-tools/adb shell am broadcast -a io.appium.settings.wifi --es setstatus disable";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(ADB+cmd);
pr.waitFor();
I am trying to send differents commands into a java program to start my solr server
My problem is that I a trying to send first the command
cd ~/Desktop/PPE/solr-4.10.3/example
and then
java -jar start.jar
Using the line
Runtime.getRuntime().exec(cmd);
Bug I get an error no such file available. Do you have any idea ?
java -jar /path/to/file/start.jar
you have not given the path of the jar file. This is why it is giving this error, and I hope you have java in your environment variables.
I have written a code (Java using eclipse Juno) which uses plink (C: installation) to connect to a remote server.
String command = "C:\\Program Files\\PuTTY\\plink -load session-name -l login -pw password";
Process p = runtime.exec (command);
Is there anyway I can safely export it (putty/plink) along with the jar file. This is so as there would not be any need of separate installation. I would also have to alter the code to call plink locally.
Thanks.
Use jar utility that comes with Java SDK to package putty executables to your application jar file.
Upon installation you can extract your exe file to a folder. And later call it from your code.
I am using the below code in plink.
"C:\Users\YXS8699\Desktop\Desktop\ansi165\x86\ansicon.exe \"C:\Progra~1\PuTTY\plink.exe\" ";
It was working fine.
Now when we run the plink command to connect WYSE50 terminal. I am facing the below issue
Command Prompt:
"C:\Program Files\PuTTY\plink.exe" CPHPQPU1.homedepot.com -l dbxd -pw 123summer -t WYSE50
Using keyboard-interactive authentication.
Password:
Now it is not working fine. Please give me some inputs.
Regards,
Yellappa
I am using the following code to execute an SH file in Linux
Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", file.getPath() });
This code works however I can't use the screen command in the SH file when executing it from Java, I get this error
Must be connected to a terminal.
So is it possible to "connect" java to a terminal? I would like to be able to also view this screen when I connect via SSH so I think it has to be connected to the terminal that is shown when you SSH into the server.
I found that if I use screen -dm it will work. Thanks!