Executing terminal command using JavaCode
Hi,
My requirement is to set JVM heap memory -Xms and Xmx using java code.
I search for this and find out a solution for windows. Wanted a similar solution for Mac as well.
Here is the code which i used for Windows.
Runtime.getRuntime().exec("cmd.exe /c java -Xms250m -Xmx1024m -jar \"application.jar\" /n");
Can any one tell how i can achieve similar kind of functionality for Mac.
Thanks,
Hi,
Thanks for replying.
I has try these but no success
*proc = Runtime.getRuntime().exec("Terminal java -Xms250m -Xmx1024m -jar \"Application.jar\" /n");
proc = Runtime.getRuntime().exec("java -Xms250m -Xmx1024m -jar \"Application.jar\" /n");
proc = Runtime.getRuntime().exec("/usr/bin/open -a Terminal java -Xms250m -Xmx1024m -jar \"Application.jar\" /n");*
Please let me know where i doing wrong
Similar Messages
-
Terminal Commands Using AppleScript
Hi,
I have some AppleScripts that access Terminal to send some commands to an Arduino.
I'm hoping there's a way to keep Terminal from opening a new window each time
I access it with a command?
Thanks,
CarlAre you using "do shell script" to execute your commands? The "do shell script" does NOT open a terminal window.
The Terminal does not execute commands, it is just a viewing device and keyboard handler for humans. The Terminal just passes your keyboard input the the shell and/or programs you run from the shell, and displays what the shell and programs run from the shell return.
The Terminal itself is not needed to run Unix commands. The "do shell scrpt" is one way to execute commands without the need for the Terminal. -
Hi,
I would like to execute terminal (DOS) command clear screen (cls). I wrote the following lines in class file:
static Process p;
try {
p = Runtime.getRuntime().exec("cls");
catch(IOException e) {
System.err.println(e.getMessage());
System.exit(-1);
I was hopping this will clear terminal. Unfortunately java throws following exception:
CreateProcess: cls error=2
I'm wondering why? Could anyone help me what is wrong.
Thanx in advance.
Best regartds, Dusan B.If you're trying to clear the dos console that your java app is working in, that won't work (unless you do System.out.prinln() a bunch of times) If you're trying to clear some other dos process, you'd have to somehow manage to join your java process and this other dos process. If you're just trying to run cls, you'll be running this without a console window so it's meaningless.
In short, whatever you're trying to do, it probably can't be done using Runtime.exec -
Executing terminal command at startup
What is the easiest way to execute a terminal command when OSX starts up?
OS X has used Launchd to run startup items since Tiger (10.4). Create a .plist for the program
you want to run and putting it in the /Library/launchAgents or the $HOME/Library/LaunchAgents
directory, if you only want it to run at user login. Optionally, for user startup items, you can add
the command to the Account login items, but it has to be in the form of a standalone unix script
or automator app to work correctly as an Account login item.
Here are some background resources on launchd:
http://www.macgeekery.com/tips/allabout_launchd_items_and_how_to_make_oneyourself
http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemS tartup/Articles/LaunchOnDemandDaemons.html
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/m an5/launchd.plist.5.html
Here is a Gui app that can help you create launchd items:
http://sourceforge.net/projects/lingon/files/
Here is a thread on using Account login items to launch scripts and automator apps:
http://discussions.apple.com/message.jspa?messageID=11569184#11569184
Now, go start something. -
Executing a command using Runtime Class
How to execute a command on a differnet machine with different ipaddress using Runtime Class
My code is
String[] cmd = new String[3];
cmd[0] = "192.1...../c:/WINNT/system32/cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = args[0];
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
This is not WorkingI have same issue. Actually when I use cmd.exe /c set in java code and if I run the java code in DOS propmt, it retrieves all latest user Environment variable values. But if I run the code in windows batch file, it is not retrieveing the latest user environment values until I reboot my computer, Do you know how to get user environment value with out rebooting machine??????
-
Getting an error while executing ddl commands using dblink
Hi,
i am using Oracle9iR2 Version.
i have created a procedure like below to execute ddl commands on remote database through dblink using dbms_sql.
CREATE OR REPLACE PROCEDURE run_remote_ddl (p_dblink VARCHAR2, qry VARCHAR2)
AS
c_handle NUMBER;
feedback INTEGER;
stat VARCHAR2 (2000);
BEGIN
stat := 'select DBMS_SQL.open_cursor' || p_dblink || ' from dual';
EXECUTE IMMEDIATE stat
INTO c_handle;
stat :=
'begin DBMS_SQL.parse'
|| p_dblink
|| ' ('
|| c_handle
|| ','''
|| qry
|| ''', DBMS_SQL.v7); end;';
EXECUTE IMMEDIATE stat;
stat :=
' select DBMS_SQL.EXECUTE' || p_dblink || '(' || c_handle
|| ') from dual';
EXECUTE IMMEDIATE stat
INTO feedback;
stat :=
'declare x integer; begin x:= :1; DBMS_SQL.close_cursor'
|| p_dblink
|| '(x); end;';
EXECUTE IMMEDIATE stat
USING c_handle;
END;
when i run this procedure like below
begin
run_remote_ddl ('@dblink', 'create table scott.ttt(num number)');
end;
got an error:
ORA-06553: PLS-103: Encountered the symbol ".2" when expecting one of the following:
. ( * @ & = - + ; < / > at in is mod not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between ||
The symbol ". was inserted before ".2" to continue.
ORA-06512: at RUN_REMOTE_DDL", line 9
ORA-06512: at line 2
Please tell me how to resolve this.
Thanks in advance.Hi,
>
ORA-06553: PLS-103: Encountered the symbol ".2" when expecting one of the following:
. ( * @ & = - + ; < / > at in is mod not rem
<an exponent (**)> or != or ~= >= <= <> and or like
between
>
Hope you are not typing 2 instead of @ as both are on the same key
Can you run the following and see what is happening
CREATE OR REPLACE PROCEDURE run_remote_ddl (p_dblink VARCHAR2, qry VARCHAR2)
AS
c_handle NUMBER;
feedback INTEGER;
stat VARCHAR2 (2000);
BEGIN
dbms_output.put_line(p_dblink);
stat := 'select DBMS_SQL.open_cursor@dblink from dual';
--stat := 'select DBMS_SQL.open_cursor from dual';
EXECUTE IMMEDIATE stat
INTO c_handle;
END;
exec run_remote_ddl('@dblink', 'create table scott.ttt(num number)');Regards
Edited by: yoonus on Feb 20, 2013 3:47 AM -
Problem while executing a command using exec()
I'm trying to execute a command on Unix O/S with the help of java program. For this I have used Runtime class available in java.lang. It works fine for some of the basic unix commands like 'ls','cp' but when I tried to execute command "sqlldr userid=<user>/<pwd> control=/u01/dw/snb/log/sp_shd05721_ins_stg_sqlldr.ctl" , then it's not getting executed. Please advise.
You may be having a problem with the command path, which I don't think Runtime.exec() uses. Try specifying the full path
-
Execute unix command using java
Hello
Can we execute a unix command using java? If it is how we can execute. Is this affect the performance of the program.
ThanksI tried what you said. But its not working and returning error message,
java.io.IOException: CreateProcess: ls -a error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
If i try this statement,
Runtime.getRuntime().exec("c\windows\notepad");
It is working fine.
Any idea about this.
Plz ........... -
To execute external command using RFC_REMOTE_exec
Hi
i want to execute the ext command using RFC_REMOTE_EXEC .
i have used like below in WINDOWS XP:
data: v_cmnd(120) type C VALUE 'dir C:\SAP\rfcsdk\bin >RFEXEC -D ESM_R'.
call function 'RFC_REMOTE_EXEC' destination D_DESTI
exporting
command = v_cmnd
exceptions
system_failure = 1 message D_ERMSG
communication_failure = 2 message D_ERMSG.
manually at command line the program getting registerd but
not throuergh RFC_REMOTE_EXEC
in v_cmnd what is the exact value we have to give
Regardsyou create the command in SM69 with some name and Directly give the Same name when you are executing.
Check this Function also.
SXPG_COMMAND_EXECUTE -
Execute SQLPLUS command using JDBC
Hi,
I was wondering if its possible to execute sqlplus command (eg set define off, change date format ..etc) using JDBC ?
Can anyone please post me some sample codes about this ?
Any help will be appreciatedHi,
But the Runtime.exec() and the JDBC application have
their own connection to the database, and the sqlplus
commands that i need to run are session based (only
valid during the connection). eg set define off
How do I overcome this ?
Huh?
You put anything you want into a input file. You feed the input file to sqlplus. If there are results then you put them into an output file.
None of that has anything to do with JDBC nor even with java. When you call Runtime.exec() you are running a completely different process. What you do with that process is up to you. -
Problem to execute cvs command using Runtime.exec method
Hello,
I want execute this cvs command, with this options:
cvs -d :pserver:[email protected]:/home/cvs/cvsroot rlog -S -d "2007/05/01<now" Project
I tried to execute with Runtime.exec() :
Runtime.exec("cvs -d :pserver:[email protected]:/home/cvs/cvsroot rlog -S -d \"2007/05/01<now\" Project");
But I have an error because the smaller character is interpretate as a redirection, no as a smaller symbol.
How I can do to use this command with Runtime.exec ?
Thanks.
Regards.Sorry,
I had a typing mistake.
I want say:
Runtime.exec("cvs -d :pserver:[email protected]:/home/cvs/cvsroot rlog -S -d \"2007/05/01<now\" Project");
Regards. -
Executing a command using back-quotes appears to hang
I have posted this to the apache users mailing list due to the evidence to date, but since I also found some reference on the web to some, admitedly old, bugs regarding unclosed input pipes which seems to cause a similar hang I thought I'd also post here and see if anyone has any ideas as to where the problem might lie. ie with apache, with /bin/sh etc etc
We have several webservers currently running on apache httpd v2.2.3. They are started and stopped by a wrapper script which at some point simply calls "apachectl stop" or "apachectl start" to control the webserver. This is all working fine, we have had no issues with it.
I am currently trying to upgrade to v2.2.6 but have run into a problem. In the wrapper script, apachectl is called in back quotes. For example we would call it as follows in order to check the output for errors:
STARTUP=`<path>/apachectl start 2>&1`
When we use this construct to start httpd v2.2.3 it works fine. When we use it to start httpd v2.2.6 the command simply hangs there without exiting. I have tried doing this directly on the command line (as opposed to within a script) and get exactly the same.
However, the webserver process has started. I can access the webserver and if I run "apachectl stop" from another terminal, a few seconds later the hung command returns to the command prompt (or the script continues if called within the wrapper script).
I am running this on a Sun sparc V480 with solaris 9 installed (kernel patch 117171-05). Apache httpd is compiled with Sun Studio 8 (I have tried Studio 11 as well and get the same results).
Configure line was:
./configure prefix=<path to install> enable-so --enable-mods-shared=all \
enable-module=so with-mpm=worker --enable-nonportable-atomics=yes \
enable-proxy=shared enable-proxy-http=shared --enable-ssl=shared \
enable-cache=shared enable-file-cache=shared \
enable-disk-cache=shared enable-mem-cache=shared
I realise that this may not actually be a problem with apache itself, in fact it seems unlikely, but the only lead I have to go on at the moment is that, on my system, it doesn't happen with v2.2.3 and does with v2.2.6 and after comming up with a total blank on the search engines I am posting here in the hope someone has encountered something similar.
Regards,
SeanDarren,
I ran a truss on the parent process while runinng the two commands as you suggested, the following was the basic difference with all leading and trailing output removed. I must admit to not being particularly adept are reading truss ouput.
When running "apachectl start"
time() = 1194348702
lwp_sigmask(SIG_SETMASK, 0x00020002, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
fork1() = 8525
lwp_sigmask(SIG_SETMASK, 0x00020002, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
setpgid(8525, 8525) = 0
lwp_sigmask(SIG_SETMASK, 0x00000000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
lwp_sigmask(SIG_SETMASK, 0x06820000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
ioctl(255, TIOCGSID, 0xFFBFF654) = 0
getsid(0) = 16141When running "A=`apachectl start`"
time() = 1194349187
pipe() = 4 [5]
lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
lwp_sigmask(SIG_SETMASK, 0x00000000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
lwp_sigmask(SIG_SETMASK, 0x00020002, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
fork1() = 9122
lwp_sigmask(SIG_SETMASK, 0x00020002, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
setpgid(9122, 16147) = 0
lwp_sigmask(SIG_SETMASK, 0x00000000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
sigaction(SIGCLD, 0xFFBFF278, 0xFFBFF318) = 0
close(5) = 0
Received signal #18, SIGCLD, in read() [caught]
siginfo: SIGCLD CLD_EXITED pid=9122 status=0x0000
read(4, 0xFFBFF3D8, 128) Err#4 EINTR
lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
waitid(P_ALL, 0, 0xFFBFECB0, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG) = 0
waitid(P_ALL, 0, 0xFFBFECB0, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG) Err#1
0 ECHILD
setcontext(0xFFBFED20)
read(4, 0xFFBFF3D8, 128) (sleeping...)
**** HERE is where the truss output hangs untill I run "apachectl stop" in another terminal ***
read(4, 0xFFBFF3D8, 128) = 0
close(4) = 0
lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
lwp_sigmask(SIG_SETMASK, 0x06820000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
ioctl(255, TIOCGSID, 0xFFBFF1E4) = 0
getsid(0) = 16141Sean -
I was wondering how I can execute commands you would normally run through a terminal (not just bash commands) through a C++ program? And how would I display the output of the command? I'm thinking fork() and execve()?
Thanks. Here's the modified code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(int argc, char *argv[]) {
FILE *pipe;
char *output;
int bytesRead;
size_t size = 100;
pipe = popen(argv[1], "r");
if(!pipe) {
std::cout<<"Unable to open pipe.";
return 1;
output = (char *)malloc(size+1);
while(!feof(pipe) {
bytesRead = getline(&output, &size, pipe);
std::cout<output"\n";
if(pclose(pipe) < 0) {
std::cout<<"Could not run"<<argv[1]<<" or other error.";
return 1;
std::cin.get();
return 0;
EDIT:
If I try making pipe a global variable I get "/home/isaac/documents/code/rtServer/main.cpp|10|error: 'FILE* pipe' redeclared as different kind of symbol|"....What's going on?
Last edited by oib111 (2009-07-20 21:36:52) -
Problem with executing SPARQL command using jdbc or jena in Java
Hi everybody
I am new to Oracle and SPARQL, so I'm sorry if my question is the elementry one!
select s, p, o from table(SEM_MATCH( '(?s ?p ?o) (?s <htt...> ?o) ', SEM_Models('OWlTEST'), null, null, null ))
I have an SPARQL command which runs on Oracle correctly and returns 8 Rows. So far so good!
I tried two ways to use this command in java code:
Using java.sql.jdbc
stmt = conn.createStatement();
rs = stmt.executeQuery(...the whole command above ....);
if (rs.next()){
System.out.println(rs.getString("O"));
Problem: resultset returns only One row, which is the first row, althogh in debug mode I can see validRow=8!!!
Using com.hp.hpl.jena
Model model = ModelFactory.createDefaultModel();
String queryStr = "PREFIX : <.....> SELECT ?s ?p ?o FROM <...> WHERE {?s prefix:property ?o}";
Query query = QueryFactory.create(queryStr);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
com.hp.hpl.jena.query.ResultSet results = qexec.execSelect();
for (;results.hasNext();) {
Problem: it returns nothing!!
Do you any Idea,
Thanks in advance
SaraSara,
I don't know about SPARQL not about jena, but for Java you need to change:
{code}
if (rs.next()) {..
{code}
to
{code}
while (rs.next()) {..
{code}
Otherwise you just fech and see only first row.
Look at : http://www.java2s.com/Code/JavaAPI/java.sql/ResultSetnext.htm
HTH
Thomas -
Failing to execute multiple commands using psexec
Trying to export hostname and disks that are in failed and predictive failure mode but psexec is failing to export hostname and predective failure disk information, it just giving failed disks information.
psexec \\<<HOSTNAME>> cmd /c HOSTNAME^&"c:\Program Files (x86)\Compaq\Hpacucli\Bin\hpacucli.exe" ctrl all show config |find "Failed|Predictive Failure"As your command is written, the find is applied to the output of the entire
psexec command, not just hpacucli.exe. You need to escape the pipe character just as you did the ^&:
^|find. Also, if you're trying to look for
either "Failed" or "Predictive Failure" you're better off using the
findstr command:
^| findstr /c:"Failed" /c:"Predictive Failure"
Maybe you are looking for
-
I just updated iTunes to 11.1.4.62 and it doesn't recognize my iPod.
Hello All! I've just recently updated iTunes to the latest version but it no longer recognizes any of the iPods in my house. It shows up in Windows but for some reason when I open up iTunes, iTunes just doesn't recognize that it's plugged in. I've
-
Site to Site VPN working without Crypto Map (ASA 8.2(1))
Hi All, Found a strange situation on our ASA5540 firewall : We have couple Site to Site VPNs and also enable cleint VPN on the ASA, all are working fine. But found a Site to Site VPN is up and running without crypto map configuration. Is it possible
-
Reg:IDOC -sales order creation
Hi All, I am trying to create sales order through IDOCS.Basic type is SALESORDER_CREATEFROMDAT201. My requirement is to know any user-exits where in I need to add to my code to hardstop sales order creation if the storage location which I am pa
-
Strange date/time in App. Builder
I just noticed that the executable file that was created by using App. Builder always showed differenct date/time from the current date/time. Anyone could give me an idea what is wrong? How can I set it to the correct date/time? Thank you in advance
-
Only first subtitle line is shown since last AppleTV 2 update
Hi, I use handbrake to encode video with soft subtitles, since the last software update It only shows the first subtitle line for everything I've encoded, is anyone experiencing the same problem? Does anyone know a solution? Thanks in advance!