0

I am trying to run a command using ProcessBuilder as below.

String[] cmdList = {"cmd.exe","/C","M:", "cd Test_SrcCd_Dev_Dyn","cleartool lsactivity -l TestActivity@My_PVOB"};
ProcessBuilder builder = new ProcessBuilder(cmdList);

From a command perspective I am basically want to asking process builder to do this.

1.Open cmd.exe

2 Open M:

3 cd Test_SrcCd_Dev_Dyn

4 Run my command i.e. cleartool lsactivity -l TestActivity@My_PVOB

My code returns null. Can someone please suggest the right way of creating the process builder to achieve the same.

Thanks in advance.

user2732988
  • 71
  • 3
  • 12

1 Answers1

-1

Did you checked documentation for process builder? public ProcessBuilder directory(File directory) this methods sets working directory for new process. Just start new process for cleartool lsactivity -l TestActivity@My_PVOB command and set its working directory to builder.setDirectory(new File("m:\Test_SrcCd_Dev_Dyn"));

It is possible that you will have to set absolute path for your cleartool

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Hi @Antoniossss..I got the below error when i tried this. Cannot run program "cleartool.exe lsactivity -l TestActivity@My_PVOB" (in directory "M:\Test_SrcCd_Dev_Dyn"): CreateProcess error=2, The system cannot find the file specified. – user2732988 Sep 06 '13 at 11:46
  • Like I wrote before in last line, you probably has to specify absolute path to program you are about to lunch, or relative path to your current directory (of java application). In your case it will be i think `M:\Test_SrcCd_Dev_Dyn\cleartool\lsactivity -l TestActivity@My_PVOB` – Antoniossss Sep 06 '13 at 18:42