Executing Operstaing System command
Hi,
I want to execute an operating system command from my java program. I tried running dir command Runtime classes exec function, but It raised an exception "CreateProcess: dir error=2". I'm using win2k as an operating system.
Could somebody please help me?
Thanks
Manjula
Hi !
Using the Runtime class u can execute any exceutable file on the OS like the exe or com on windows. There is no executable file called dir... Instead put the dir command in xxx.bat file and then try executing the batch file.
I hope this helps...
Regards,
Vin
Similar Messages
-
Vista: use the windows program manager to execute operating system commands
attempting to run forms 6 on vista... the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.
in windows vista i get a message box indicating "use the windows program manager to execute operating system commands".
is this windwos vista message? would this have to do with permissions?
any insight most appreciated and thanks in advance.I don't know about the HOST-problem, but..
the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.What about putting the logic from the SQL*Plus-scripts into a database-procedure and call that instead. I think,, with the current approach you will get problems at least when you have to migrate to Web (e.g. Forms 10g). -
Executing operating system command within trigger or procedure
Hello
Can some one help me out as how to execute operating system command (unix or windows ex.. stop,start,cc,del or copy etc...) in a trigger or procedure.
My requirement is, if some predefined error occure then listener listener should be stopped automatically.
Thanks in advance
kvssHere is some code to tell you how to do:
First a small Java program that taker a string as a parameter and executes it as an os-command
import java.lang.Runtime;
import java.lang.Process;
public class Commands extends Object {
* Constructor
public Commands() {
// On NT the command should be like this "cmd /c del c:\temp\readme.txt"
// exec execute('cmd /c del c:\temp\readme.txt');
public static void execute (String cmd ) {
try {
Process p = Runtime.getRuntime().exec(cmd);
try {
p.waitFor();
catch (java.lang.InterruptedException intex ) {
intex.printStackTrace();
System.out.println("Return = "+ p.exitValue());
System.out.println(" Done ...");
catch ( java.io.IOException iox) {
iox.printStackTrace();
===================end of java ====
Use loadjava to load it into the database and create a pl/sql wrapper around the java code.
See the manual about loadjava details.
Log in to sqlplus as SYSTEM and create a role for this purpose e.g. 'JAVA_ROLE'
and exec the following as SYSTEM or SYS to make sure the user has the the needed privs.
dbms_java.grant_permission('JAVA_ROLE','SYS:java.io.FilePermission','<<ALL FILES>>','read,write,execute,delete');
dbms_java.grant_permission('JAVA_ROLE','SYS:java.lang.RuntimePermission','writeFileDescriptor',null);
dbms_java.grant_permission('JAVA_ROLE','SYS:java.lang.RuntimePermission','readFileDescriptor',null);
and you're done. -
How to execute a system command on a remote UNIX server?
I would like to execute a system command (for example "df") on a remote UNIX machine.
A simple example would be welcome...
ThanksI would like to execute a system command (for example
"df") on a remote UNIX machine.
A simple example would be welcome...None will be forthcoming.
Executing a process is relatively simple. However doing this on a remot system is another matter.
See http://sourceforge.net/projects/sshtools/
and/or http://javassh.org/space/start
Other resources to be found with Google. -
How to execute a system command with call executable in teststand 4.2.1?
Hi All,
how to execute a system command with "call executable" step in teststand 4.2.1?
example as i want to quit a application.using "taskkill /f /im xxx.exe".And execute other system command(DOS).
BR
JohnnyHi,
I want to run netstat -an | find "8080" command from command prompt using call executable in test stand. after that i would like take the std output to local variable.
Attachments:
callsettings.jpg 404 KB -
How to: execute operating system commands from PL/SQL
System: IBM pSeries AIX
Oracle: 11g Enterprise
Is there a quick way to execute operating system commands from PL/SQL?
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.Is there a quick way to execute operating system commands from PL/SQL?
NO
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
WHY ON EARTH, such action will create a new connection and become a resource hog?
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Which is perfect for the purpose.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.
NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
Sybrand Bakker
Senior Oracle DBA -
How to execute Operating System commands from Stored procedure.
Any help on how to execute Operating System commands from stored procedures will be appreciated.
Nanditha.Search the forums for 'External Procedure' and you will find example code that has been posted before.
-
Executing Operating system commands in ABAP
Hi
I want to execute a unix operating system command in an ABAP program. I remember seeing code which executes an operating system command. Could any please let me know about that code?
Thank You.
EswarHi,
you can try something like this.
data:cmd(254) type c.
data: RESULT(255) OCCURS 100 WITH HEADER LINE.
cmd = 'ls'.
** Execute command
REFRESH RESULT.
CALL 'SYSTEM' ID 'COMMAND' FIELD CMD
ID 'TAB' FIELD RESULT-*SYS*.
Kostas -
Permission problems when trying to execute simple system command
Hi, I am quite new to JSP so please forgive me if I ask really simple things... I am trying to run system commands on the server and display the output on a webpage. This is what I've got:
<%@ page import="java.io.*" %>
<HTML>
<BODY>
<%
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("/bin/ls");
// for reading the output of the program
// (out of the program is in for us)
BufferedReader sOut = new BufferedReader(new
InputStreamReader(p.getInputStream()));
// read the output
String line;
while ((line = sOut.readLine()) != null)
out.println("line<BR/>");
%>
</BODY>
</HTML>However, when I run this, I get the following:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /research/test.jsp:7
4: <%
5: Runtime rt = Runtime.getRuntime();
6:
7: Process p = rt.exec("/bin/ls");
8:
9: // for reading the output of the program
10: // (out of the program is in for us)
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
root cause
java.security.AccessControlException: access denied (java.io.FilePermission /bin/ls execute)
java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
java.security.AccessController.checkPermission(AccessController.java:546)
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
java.lang.SecurityManager.checkExec(SecurityManager.java:779)
java.lang.ProcessBuilder.start(ProcessBuilder.java:447)
java.lang.Runtime.exec(Runtime.java:593)
java.lang.Runtime.exec(Runtime.java:431)
java.lang.Runtime.exec(Runtime.java:328)
org.apache.jsp.research.test_jsp._jspService(test_jsp.java:49)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
Seems like it has something to do with the permissions granted to the JVM? I have googled high and low and still haven't found a way to solve it. I've also tried adding grant { permission java.io.FilePermission "file:/bin/ls", "execute"; } to my java.policy file but to no avail. Could somebody point out how to solve this? Thanks!I would think it is an OS permission thing rather than java permission
What user is apache running as on this system?
Does the user apache is running as have permissions to run these commands, in the directory where you are running them? Try executing them yourself when logged in as that user.
I would also recommend you read the article [when runtime.exec() won't|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html].
Cheers,
evnafets -
How to execute operation system commands by using TSQL without enabling xp_cmdshell.
Hi Experts
Looking for advise if one can use operation system commands using TSQL without enabling xp_cmdshell.
actually using xp_cmdshell requires sysadmin privs which I am unable to provide (directly or using proc) to a user but the user needs some operating system commands to execute for file manipulation from sql server session. Please share your thought.
Best Regards
khalil>but the user needs some operating system commands to execute for file manipulation from sql server session
See article here
http://www.mssqltips.com/sqlservertip/2014/replace-xpcmdshell-command-line-use-with-sql-server-agent/:
"Problem
I need to run something from the command-line, but based on best practices xp_cmdshell has been disabled. The task that needs to run is an internal process that will originate from within SQL Server. Is there a way to do this without using xp_cmdshell?
Solution
The use of xp_cmdshell is generally frowned upon and is now recommended to be disabled, unless it is absolutely necessary. There is a solution that works around this restriction via the use of SQL Server Agent.
Wherever SQL Server is installed, SQL Server Agent is installed with it (except for SQL Express). SQL Server Agent has the ability to run job steps which invoke the command shell. And in the case that the job is owned by a member of the sysadmin fixed server
role, the job will execute as the service account under which the SQL Server Agent is running. "
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
Executing Operating system command
I have a file(ftp)-xi-file(ftp) scenario. I want to run a operating system command on output/processed file which is on a different physical server through a script. But I have seen my script is not working. But when I did the same on the same physical server on which XI is hosted it is working fine. Could you plz somebody advise whether it works ?? if it is the case what precaustions should we take ??
thanks
kumarHi Palnati
OS command will run on XI OS only so you need to use FTP parameter in the script and "permanent connection" as connection mode
Check this thread also
Re: FTP ReceiverChannel and OS commands help
Thanks
Gaurav -
Executing one system command from one java class. ERROR. Please help me
Hello i am trying to add users into one linux machine using one jaav program but when i execute the java class the system doesn't show me any error and dont make anything.
The linux command, in the main of the class, is correct; from thelinux shell it runs well, but from the java class it doesn't run.
Can you help me please?
thanks
import java.io.*;
public class ejecutaUsuario {
/** Creates a new instance of ejecutaUsuario */
public ejecutaUsuario(String cmdline) {
try {
String line;
Process p = Runtime.getRuntime().exec(cmdline);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
input.close();
catch (Exception err) {
err.printStackTrace();
System.out.println(err);
public static void main(String argv[]) {
String passwd="hola";
String usuarioInterno="xxxxxx";
new ejecutaUsuario("/bin/sh useradd -p `openssl passwd -1 -salt 12345678 " + passwd + "` -d /home/" + usuarioInterno + " -m -s /bin/bash " + usuarioInterno);Try gettting the error input stream as well (getErrorStream()). Maybe you are getting output there.
You might want to try just executing the 'useradd' part, getting the output stream of that process, and then put the parameters of useradd into the outputstream.
Later
Cardwell -
How to execute system specific command from Java ?
I know it was done with System(String command); in C/C++.
Or is it possible at all ?Runtime.getRuntime().exec(...)And, read this:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
Executing Operating system commands
Hi,
I need to execute sql*loader from APEX(sqlldr scott/tiger CONTROL=ulcas1.ctl ). How can I implement this in APEX. In oracle forms , I can execute this by a trigger when-button-pressed in a push button - host('sqlldr scott/tiger CONTROL=ulcas1.ctl ').
Regards
JIJUI took the mention of the Forms method to indicate that the requirement was another manifestation of that currently popular meme Calling calc.exe from APEX
(At least I've thought there was a lot of it about at the moment...)
@Jiju - there is no equivalent of host in ApEx. You can write your application to allow files to be uploaded to the server and parsed by your application, or written to the server file system and read as an external table. There are a lot of threads about this kind of thing in this forum: search for "file upload"... -
PL/SQL: how to execute host-/system command without ext. procedure call
Hello,
I would like to execute a systemcall out of a PL/SQL-package (e.g. execute a shell script). Seems like that this is just possible with a external procedure call.
Are there any other solutions available?
Rgds
JHWith 10g you can use DBMS_SCHEDULER: see Re: Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch fi
Maybe you are looking for
-
Hi everyone Can someone tell me how I can reset my icloud calender from pacific time zone to australian western ,it keeps reverting back to pacific all the time cheers
-
How to insert a sev lines in the comments field for the Nc detail report?
Hi, I have tried to send in comments in the Nc log via soauip interface to SAP, but i'm only managing to get all the text in one long line. Is it possible to divide the text to several lines? Br, Mattias
-
Creation of sales order with reference to Quotation using BAPI
Hi All, I am using BAPI "BAPI_SALESORDER_CREATEFROMDAT2" for creating sales order. Can you please tell how can I create a sales order with reference to a Quotation.
-
Combobox Autocomplete editor inside Jtable cell
I have a custom combobox editor which supports the autocomplete feature as follows: as soon as the user keys in any character, this editor searches for the item that starts with keyed in character. This item is displayed in the editor text field and
-
ITunes locks up frequently during importing process
Problem started after successfully ripping about five CDs. Purged the start up sequence of programs that may have been intruding on the iTunes signal and that worked for a good spell. After ripping about 1300 songs, the problem started again and I'm