0

I want to run specific code with C# windows application on cmd(command prompt) for sign jar file. I used this code

System.Diagnostics.Process.Start(@"cmd", @"/K ""c:\program Files\Java\jdk1.6.0_23\bin\jarsigner.exe"" -keystore filepath.p12 filepath.jar ""alias_name""");

I encountered this error while I executing this code

Error:

'c:\program' is not recognized as an internal or external command,
operable program or batch file.

How can I solve this problem ?

dgn
  • 103
  • 5
  • 15
  • Could not reproduce: i used `System.Diagnostics.Process.Start(@"cmd", @"/K ""c:\program Files\winrar\winrar.exe"" t c:\test.rar");` and it worked as expected... – C.B. Oct 31 '13 at 13:47
  • This code works.But my jarsigner.exe command dont work.If I write directly to cmd ,code works and ask for password for jar signature. But I encountered this error while executing from Visual Studio – dgn Oct 31 '13 at 14:15
  • Any reason not to have `System.Diagnostics.Process.Start(@"c:\program Files\Java\jdk1.6.0_23\bin\jarsigner.exe", @"-keystore filepath.p12 filepath.jar ""alias_name""");`? – C.B. Oct 31 '13 at 15:06
  • It works.Why other command didn't work? System.Diagnostics.Process.Start(@"cmd", @"/K ""c:..."); – dgn Oct 31 '13 at 15:46
  • Not sure, but apparently `cmd` doesn't manage to perfectly dispatch its parameters to the command included after the `/K` option. Luckily, bypassing the cmd intermediate and using the "Starts a process by specifying the name of an application and a set of command-line arguments" feature of Process.Start removes the disturbance of the "3rd-party". :) – C.B. Oct 31 '13 at 16:33

1 Answers1

1

From the comments above, i understand this solves the issue:

System.Diagnostics.Process.Start(@"c:\program Files\Java\jdk1.6.0_23\bin\jarsigner.exe",
    @"-keystore filepath.p12 filepath.jar ""alias_name""");

Happy signing. ;-)

C.B.
  • 666
  • 3
  • 18
  • After executing this code jarsigner ask for password. If I write password, cmd screen disappears.I searched some site for this.It says put "/K" keyword .How can I use /K with this code? – dgn Nov 01 '13 at 08:46
  • The "/K" option is for a "cmd" process, not specifically related to jarsigner. But if you really want to use `cmd` you could write the `"c:\program Files\Java\jdk1.6.0_23\bin\jarsigner.exe" -keystore filepath.p12 filepath.jar "alias_name"` into a batch file (say, "signfile.bat"), and execute `Process.Start("cmd", "/K signfile.bat")`... HTH. – C.B. Nov 01 '13 at 10:33
  • If you want to stop the jarsigner asking for a password you need to include the _storepass_ switch as per below. `System.Diagnostics.Process.Start(@"c:\program Files\Java\jdk1.6.0_23\bin\jarsigner.exe", @"-keystore filepath.p12 -storepass TheStorePassword filepath.jar ""alias_name""");` HTH :) – Lee James Dec 17 '14 at 09:31