Problem in executing command prompt commands through application
Hi,
I am facing issue in executing commands through VC++ application.
My application is a dialog based MFC application in VS2008.
I want to execute below commands programmatically.
devenv D:\TestApp\TestApp.sln /rebuild release
devenv D:\TestApp\TestApp.sln /rebuild debug
But I am not able to set the current directory path as "D:\TestApp\" programatically.
Through which API I can execute multiple commands on command prompt programmatically same as we do manually on cmd.
Please Help.
Thanks in Advance.
Thanks & Regards, Mayank Agarwal
I want to execute below commands programmatically.
devenv D:\TestApp\TestApp.sln /rebuild release
devenv D:\TestApp\TestApp.sln /rebuild debug
But I am not able to set the current directory path as "D:\TestApp\" programatically.
Through which API I can execute multiple commands on command prompt programmatically same as we do manually on cmd.
Why can you "not able to set the current directory path as "D:\TestApp\" programatically"? Are you forgetting to escape the backslashes?
Why to you need to set the current directory anyway?
What is the problem with executing multiple commands?
As to your basic goal, have you looked at
system()
ShellExecute()
ShelExecuteEx()
CreateProcess()
? Perhaps you should show us what you have tried.
David Wilkinson | Visual C++ MVP
Similar Messages
-
How to execute a Command Prompt command from J2SE code executing on Windows
How to execute a Command Prompt command from J2SE code executing on Windows??
Please help me[http://java.sun.com/docs/books/tutorial/getStarted/]
~ -
Problem with executing java on command prompt
Hi my program uses java mySQL connector to connect to a local host. The program works fine when i run through netbeans. But when i run through command prompt it gives in this error message
java.lang.ClassNotFoundException:com.mysql.jdbc.Driver Can anyone help me to solve this problemadd mysql.jar file to ur classpath, it will work fine.
-
Hi all,
I was trying to execute the following code:
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
* Created on Mar 13, 2007
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
* @author 195092
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
public class ClassReportDeleteDaemon {
ClassReportDeleteDaemon()
public static void main(String[] args) throws Exception
Connection conn = null;
Statement stmt = null;
ResultSet rs;
String strQuery = null;
String strdaysback = null;
String delstring = null;
int daysback;
try
System.out.println("REPORT DELETION ::: FINDING DRIVER");
Class.forName("oracle.jdbc.driver.OracleDriver");
catch(Exception e)
System.out.println("REPORT DELETION ::: DRIVER EXCEPTION--" + e.getMessage());
System.out.println("REPORT DELETION ::: DRIVER NOT FOUND");
try
String strUrl = "jdbc:Oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2];
System.out.println("REPORT DELETION ::: TRYING FOR JDBC CONNECTION");
conn = DriverManager.getConnection(strUrl);
System.out.println("REPORT DELETION ::: SUCCESSFUL CONNECTION");
while(true)
System.out.println("WHILE LOOP");
stmt = conn.createStatement();
strQuery = "SELECT REP_DAYS_OLD FROM T_REPORT_DEL";
rs = stmt.executeQuery(strQuery);
while(rs.next())
strdaysback = rs.getString("REP_DAYS_OLD");
//daysback = Integer.parseInt(strdaysback);
System.out.print("NO of Days===>" + strdaysback);
delstring = "find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r";
System.out.println("DELETE STRING===>" + delstring);
Process proc = Runtime.getRuntime().exec(delstring);
//Get error stream to display error messages encountered during execution of command
InputStream errStream=proc.getErrorStream();
//Get error stream to display output messages encountered during execution of command
InputStream inStream = proc.getInputStream();
InputStreamReader strReader = new InputStreamReader(errStream);
BufferedReader br = new BufferedReader(strReader);
String strLine = null;
while((strLine=br.readLine())!=null)
System.out.println(strLine);
} //end of while loop
} //end of try
catch (Exception e)
System.out.println("REPORT DELETION ::: EXCEPTION---" + e.getMessage());
conn.close();
} //end of main
} //end of ClassReportDeleteDaemon
But it is giving the error "BAD OPTION -print|xargs". The command run well in shell.
Please help.
Thanking u.......Since the pipe '|' is interpreted by the shell then you need the shell to invoke your command
String[] command = {"sh","-c","find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r"};
final Process process = Runtime.getRuntime().exec(command);
You should also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html at least twice and implement the recommendation regarding stdout and stderr.
P.S. Why are you not using Java to find and delete these files?
Message was edited by:
sabre150 -
How to run a command prompt " command " through java code
hi all,
There is a command
"java -jar selenium-server.jar -interactive"
which i am running through command prompt after going to D:\MyFolder\Examples .
i want to execute this command using java code .please helpThis has already been answered in your other two threads on this topic - http://forum.java.sun.com/thread.jspa?threadID=5221221&messageID=9898287#9898287 and http://forum.java.sun.com/thread.jspa?threadID=5221223&messageID=9898290#9898290.
For some reason you don't want to read the reference that tells you exactly how to do what you want and how to avoid the pitfalls - http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html . -
Urgent: Problem with executing an OS command
Hi, all.
My system environment is Netweaver 04 on SUSE LINUX Enterprise Server 9 (x86_64). Temporary License has been installed on the machine.
I'm trying to execute an OS command as an auto-reaction to a monitoring architecture alert.
I have followed the
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/predefined auto-reaction methods of the alert monitor
document.
I have defined operating system command in the External Operating System Command transaction (SM69). I have tested it using transaction (SM49) and it is working fine independently. I have created a auto-reaction method using transaction RZ21 and assigned to the my MTE (Monitoring Tree Element). Then I go to the transaction RZ20. When an alert is arrived to my MTE, the color get changed to Red. When I select the MTE and clicked the Display Alert, It shows the ACTION_REQUIRED status and my command is not executing because my auto-reaction method is not started.
Could someone tell me what could be the all possible reasons for this? Is there any particular service using transaction SICF I have start for this? What most important steps I am missing?
Let me know if anything more informations you people required to answer this.
Its very urgent for me. If someone help me ASAP, it would great help for me.
Thanks in advance.
Best regards,
SanjayCan you double check the auto reaction method assignment?
You do not need to have any SICF services enabled for this. -
I know that while I use the command prompt in windows to execute java application, I cannot use the other windows commands such as
ipconfig,
telnet...
etc
Is there anyway where I can use the java commands (javac, java) AND the other regular commands??The problem is happening because the PATH variable
settings is not proper.
Go to the environment variables in your machine and
append the following to the PATH environment
variable
%SystemRoot%\system32;%SystemRoot%;Save and then open a new command window and try.Yep, you were right.
I did that to the user's path and it worked after I appended it. It works for both now,
thanks. -
Runtime.exec() I need to run a command prompt command from java.
the code i have that doesn't seem to work is:
String driveloc = System.getProperty("user.dir").substring( 0, 1 );
String path = jTextFieldPath.getText();
String path2 = jTextFieldPath.getText().substring(0, jTextFieldPath.getText().length()-3) + "lst";
String[] cmd = { "cmd.exe", "/" + driveloc, "ASMtools\\AS11 " + path + " -L >" + path2};
txt_mf.append( cmd[3] );
try {
Process np = Runtime.getRuntime().exec( cmd );
catch( java.io.IOException ioe) {
//error
}jTextFieldPath.getText() contains the path of the file saved by my program.
the line of code i am trying to run is:
AS11 FILE1 -L FILE2this line compiles the asm file and converts it to a lst creating an s19 file in the process. AS11 is an exe that aids the command prompt much like javac.
If you could help me figure this out it would be great.
Thanks in advance,
-JukeString driveloc =
System.getProperty("user.dir").substring( 0, 1 );
String[] cmd = { "cmd.exe", "/" + driveloc,
"ASMtools\\AS11 " + path + " -L >" + path2};Are you sure you want to invoke cmd.exe with the switch /c or /d or whatever depending on System.getProperty("user.dir") ?
Starts a new instance of the Windows 2000 command interpreter
CMD [A | /U] [Q] [D] [E:ON | /E:OFF] [F:ON | /F:OFF] [V:ON | /V:OFF]
[[S] [C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using c as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
/V:OFF Disable delayed environment expansion. -
Problem in executing a unix command through java
hi
i'm trying to execute unix command through java
simple shell command like "ls -l >test " but i'm not able to see the result.
there are no error messages.
Code is:
import java.lang.Runtime.*;
class ExecDemo
public static void main(String[] args)
Runtime r=Runtime.getRuntime();
Process p=null;
try
p=r.exec("ls -l > test");
catch (Exception e)
System.out.println("Error executing nedit.");
}can anyone help please.get the the inputStream of the runtime object after executing the command.
now use the readLine() function until it becomes null.
egs: with reference to ur code.
InputStream is=p.getInputStream()
while(is!=null)
String s=is.readLine();
if the command don't execute try giving the full path also like /sbin/ls -l -
Problems to execute "cd" DOS command from Java program
Anyone try to exec command "cd.." or "cd directory", it doesn't have any action. No exceptions, just don't do anything.
Runtime.getRuntime().exec("cd\\");
Runtime.getRuntime().exec("cd hello");
However, when I try the following, it is working fine. Any ideas???
Runtime.getRuntime().exec("explorer");
Runtime.getRuntime().exec("javac Test1.java");That's because cd is built into the command
interpreter in Windows. Runtime.getRuntime().exec()
can only be used to launch external programs. This
article should get you going:And that's not the only reason why you can't do this.
When you do
Runtime.getRuntime().exec("cd c:\\");
(or, heck, "cmd /c cd c:\\"): the new command that you spawn will cd to the destination specified, and then exit. The parent process (your java program, that is launching this command) won't go anywhere - the "cd" doesn't affect it.
The only way to change your OS directory in Java is to invoke native code. And even then, the effects are undefined (in terms of how your CLASSPATH will be affected, etc.). -
Problem in executing RunTime.exec() commands
Hello EveryBody
I have a problem.i have to zip the photos that r uploaded by the users and sumit it to the lab person.for that i zip these photos and give the lab person to download that zip.
But the problem is that when ever i zip 30 to 40 photos its work fantastic.but more the 50 photos not get zip.I have used the code as follow.
// Here tr=ru
//dest=distinaction path of the file
// src=source path of the file
try
Runtime rt = Runtime.getRuntime();
String [] cmd={"zip",tr,dest,src};
Process p2=rt.exec(cmd,null,dir2);//
p2.waitFor();
}catch(Exception e2){
out.println("HOTO EXCEPTION "+e2.toString());
Since no zip file is created for big size photo and also it not shows any error.can anybody help me it is urgent.
Thanks a lot
Rzip reports the files as it progresses. It this report is too long, zip's outpbut buffer gets filled and if you do not read it from your Java program, zip will block.
-
This is a stoopid question and I've searched the forums, but what is the command in DOS prompt to view your classpath.
When I run java -classpath it gives me all the various options e.g.
java -cp -classpath
but non of these work? whats the craic?
M.What do you mean by "none of these work"?
Suppose that you have a file HelloWorld.class in the directory C:\MyClasses. If you type:
java -classpath C:\MyClasses HelloWorld
it should run your program without problems.
Are you getting an error message? What's the error message?
Jesper -
Running command prompt commands in java
I can use:
Process j = Runtime.getRuntime().exec("command";
BufferedReader stdInput = new BufferedReader(new InputStreamReader(j.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(j.getErrorStream()));
to run commands in the command line buf if i make another process..the command will not run...any ideas?ProcessBuilder can simplify things:
redirectErrorStream
<quote>
If this property is true, then any error output generated by subprocesses subsequently started by this object's start() method will be merged with the standard output, so that both can be read using the Process.getInputStream() method. This makes it easier to correlate error messages with the corresponding output.
</quote> -
Problem accesing Executable on remote CPU through webb panel interface on client computer
Hi,
I am using LabVIEW 2009 to acces a program "Test.exe" in a server computer. I take it from the forums as it should be possible to bulid a Test.exe with Publishing Tool functionality so its panel can be accesed only with a browser from a client computer. This is how it is setup.
Server CPU (pesno111.company.se):
Labview Run time Engine 2009 SP1
Activated NI License manager
Everything installed from an Installer that also had NI Labview 2009 SP1 Deployable License
Then Test.exe is started and its Test.ini looks like this:
[Test]
server.app.propertiesEnabled=True
server.ole.enabled=True
server.tcp.serviceName="My Computer/VI Server"
server.vi.propertiesEnabled=True
postScriptLevel2=False
WebServer.Enabled=True
WebServer.RootPath=C:\Program Files\National Instruments\LabVIEW 2009
WebServer.TcpAccess="c+*"
WebServer.ViAccess="+*;-Power Spectrum Measurement.vi;-Power Spectrum Measurement.vi"
DebugServerEnabled=False
DebugServerWaitOnLaunch=False
The Test.html file (see attachment) is also placed on the server computers path C:\Program Files\National Instruments\LabVIEW 2009 .
I try to acces the Test.exe from a browser in the client computer with the following path http//pesno111.company.se/Test.html
but it doesnt work. Any ideas?
Attachments:
Test.txt 1 KBHi Björkis
I would start by checking that I've followed the instructions in these two tutorials:
Remote Panels in LabVIEW -- Distributed Application Development
Developing Remote Front Panel LabVIEW Applications
Also, could be a good idea to look into if you are behind a firewall or proxy as this could cause a problem.
Best Regards
David
NISW -
System 32 command prompt commands to factory reset hp notebook 2000 laptop
Need to factory reset notebook from command prompt
Normally tapping the F11 key immediately after powering on will boot into Recovery Manager.
******Clicking the Thumbs-Up button is a way to say -Thanks!.******
**Click Accept as Solution on a Reply that solves your issue to help others**
Maybe you are looking for
-
What is the impact - Activating Change Logs for Material Classification Dta
To activate Change Logs for Material Classification Data I must first set the flag for "Multiple Objs Allowed" for the Class Type 001 Material Class. I am curious of what the impact of setting this flag will be. Also, is there a way to measure the DA
-
Hello, I use the default terminal on Mac OS X 10.4.8, which I'm lead to believe is Bash. In Bash, I should be able to use some rather advanced, and simple, wildcard expressions. However, using something as simple as: ls -a .0* gives the response "ls:
-
How to see the log file on the Reports Application server?
Hi, I am new to this Reports, please correct me if i am wrong or in the wrong forum, we have a java based front-end application which calls oracle reports to display requested reports. We are using oracle reports (9i/10g). I need work on a report, It
-
No Windows for conflict resolution in Isync
Hello, After a synchro with iSync, I see conflicts. When I try to resolve them. The resolve conflit app is launched but i have no windows. To be clear I have not the possibility to resolve conflict because the windows apps do not appears. But I have
-
Why is my firefox icon not showing it only show blank icon
Why is my Firefox icon is blank. on desktop == This happened == Every time Firefox opened == when i reinstall fire fox