Hi All,
I am using the following codeline to run a cmd from cmd prompt.

Process p1 = Runtime.getRuntime().exec("cmd.exe /k start vgnimport....
I have my structure like

Class A
B importcmd = new B();
importcmd.startimp();
sysout("out of cmd prompt");

Class B
startimport()
{
Process p1 = Runtime.getRuntime().exec("cmd.exe /k start vgnimport....
sysout("here is ur output");
}

In this case entire code of class B gets executed .i.e.the statements after i fire exec cmd
But in Class A nothing gets executed once i call this class...

Can anybody help me out of this..
Thanks in advance

I'm not 100% sure, but I think this issue could have to do with threads. I think what is happening is the cmd.exe is being run in the main thread and there is no other thread to run the rest of class A until you quit the cmd.exe. If I am correct, you need to implement a third class like so:

public class C implements Runnable
{
  public void run()
  {
    Process p1 = Runtime.getRuntime().exec(...
  }
}

Next you need to modify class B like so:

startimport()
{
  C runnable = new C();
  new Thread( runnable ).start();
  sysout("here is output");
}

For more information on Threads, see the sun website.

Thanks a lot...i will implemnt this...but what i think is if i loop throgh the cmd thosannds the threads might create a issue...
Is there some other way out?

Are you saying you want thousands of command prompts? What exactly are you trying to do in the exec line?

i am logging into the content management system throgh the command and import data into it.So i think doing it through threads could create an issue

Then why don't you just write a batch or shell script?

I am going to convert the entire program into batch file including these steps:)
Anywayz my problem is partially solved
My code was like

package com.WCM.Vignette;

import java.io.*;


public class Import_In_VCM {
	
	/**
	 * @param args
	 * @throws WCM_Exceptions 
	 * @throws  
	 *  
	 */
	void Call_From_Import() throws WCM_Exceptions  {	
	File dir1 = new File("C:\\Path");
		String s = null;
		try {
			//start the command prompt
			String[] cmds = {"cmd.exe /k start dir"};
			int i;
			for(i=0;i<cmds.length;i++)
			{
				System.out.println(cmds[i]);
			}
			
			 /*
			 * run the vgnimport command 
			 */
			
			Process p1 = Runtime.getRuntime().exec("cmd.exe /k start vgnimport -u user -p pwd -h machine:port -s  D:\\Datanew12.zip",null,dir1);
			// read the standard output of the command
			BufferedReader stdInput = new BufferedReader(new 
			 InputStreamReader(p1.getInputStream()));
    		//BufferedReader stdError = new BufferedReader(new 
				//	InputStreamReader(p1.getErrorStream()));

			// read the output from the command
			System.out.println("Here is the standard output of the command:\n");
			/*while ((s = stdInput.readLine()) != null) {
				System.out.println(s);
			}

			// read any errors from the attempted command
			System.out.println("Here is the standard error of the command (if any):\n");
			while ((s = stdError.readLine()) != null) {
				System.out.println(s);
			}
			
					 
		catch (IOException e) {
			System.out.println("hi u r in catch");
			throw new WCM_Exceptions("Exception occurred ");

			
		}
		
		
	}

}

In this code when i commented while(s = stdInput.readLine()) the prog started working
But now the problem is two command prompts are strated simultaneously for the same file.
I mean i am calling this class( Call_From_Import) from other class in a loop in which values in zip file are modified...If i use system.exit or p1.waitfor or p1.destroy only 1 cmd prompt is started

I am going to convert the entire program into batch file including these steps
Anywayz my problem is partially solved
My code was like

package com.WCM.Vignette;

import java.io.*;


public class Import_In_VCM {
	
	/**
	 * @param args
	 * @throws WCM_Exceptions 
	 * @throws  
	 *  
	 */
	void Call_From_Import() throws WCM_Exceptions  {	
	File dir1 = new File("C:\\Path");
		String s = null;
		try {
			//start the command prompt
			String[] cmds = {"cmd.exe /k start dir"};
			int i;
			for(i=0;i<cmds.length;i++)
			{
				System.out.println(cmds[i]);
			}
			
			 /*
			 * run the vgnimport command 
			 */
			
			Process p1 = Runtime.getRuntime().exec("cmd.exe /k start vgnimport -u user -p pwd -h machine:port -s  D:\\Datanew12.zip",null,dir1);
			// read the standard output of the command
			BufferedReader stdInput = new BufferedReader(new 
			 InputStreamReader(p1.getInputStream()));
    		//BufferedReader stdError = new BufferedReader(new 
				//	InputStreamReader(p1.getErrorStream()));

			// read the output from the command
			System.out.println("Here is the standard output of the command:\n");
			/*while ((s = stdInput.readLine()) != null) {
				System.out.println(s);
			}

			// read any errors from the attempted command
			System.out.println("Here is the standard error of the command (if any):\n");
			while ((s = stdError.readLine()) != null) {
				System.out.println(s);
			}
			
					 
		catch (IOException e) {
			System.out.println("hi u r in catch");
			throw new WCM_Exceptions("Exception occurred ");

			
		}
		
		
	}

}

In this code when i commented while(s = stdInput.readLine()) the prog started working
But now the problem is two command prompts are strated simultaneously for the same file.
I mean i am calling this class( Call_From_Import) from other class in a loop in which values in zip file are modified...If i use system.exit or p1.waitfor or p1.destroy only 1 cmd prompt is started

Please help me in solving the problem....

This article has been dead for over six months. Start a new discussion instead.