i'm trying to run cmd.exe in jira for which i have written the following code in java.
package com.atlassian.plugin.cli; import com.atlassian.jira.web.action.JiraWebActionSupport; public class RunCliComponent extends JiraWebActionSupport{ /** * */ private static final long serialVersionUID = 1L; public String doDefault() throws Exception { try{ Process p = Runtime.getRuntime().exec("cmd /c start cmd"); System.out.println("******"); System.out.println("test"); System.out.println("******"); }catch(Exception ex){ System.out.println(ex); } return INPUT; } }
but i get an error
java.io.IOException: Cannot run program "cmd": java.io.IOException: error=2, No such file or directory
where am i going wrong?
You need to give the code the full path to the cmd.exe executable
Sorry, I should have said - "full path" means including the full filename.
I tend not to say it because I work mostly with decent operating systems that don't make wooly assumptions about file names.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
String path = "C:/Windows/System32/cmd.exe"; Runtime rt = Runtime.getRuntime(); rt.exec(path);
dis is how i tried now..
i still get the same error. where am i going wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know. That works on the Windows VM I've got here. Could you check that cmd.exe really is there and you've got the full rights to read and execute it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes.. it is in dat path. i tried to run it as a java application on eclipse and it works perfectly.
But when i try the same by packaging in a jar and run it JIRA i get this error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm. The Jira you are installing the .jar into - could you look at the system information page and check the environment variables look ok? Specifically the paths in the environment
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I don't understand that question.
Could you tell us what the environment looks like on the Jira you are deploying to please?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is it possible to open a cmd prompt this way in a web app like jira?
If you're asking if doing this inside a plugin is sufficient to make a command prompt available on a web page, the answer is no. The CMD prompt is an interactive process and keeping it open and keeping continuous streams of information open between your web browser and the prompt are not a problem that the HTTP protocol and web browsers were really designed to tackle. It is not impossible provided you use some JavaScript libraries to provide support for it.
On the other hand, doing something like this would open a security hole to your system. If you're actually fine with allowing access to the system that is running JIRA, it is both simpler and safer just to enable sshd or Remote Desktop Connection on the server. If you don't trust people to access the system through those, then you don't trust them coming in through JIRA either. If you are trying to circumvent somebody *elses* security by uploading a rogue plugin to their system, then naturally it isn't really appropriate for us to help you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, I see.
Anisha is thinking that you can run "cmd" on the machine the *browser* is running on, but the code there is trying to open it on the Jira server (which, I'd guess, is not a Windows box, if it's missing cmd.exe)
If that is the case, then, I'm with Chris - not only is it immensely hard to open arbitrary commands on the client machine, it's a) impossible to guarantee that the command you want is present or even accessible, and b) has the potential to be an absolutely gaping security hole.
I was assuming you were trying to run something on the Jira server, which was a Windows server of some sort and has a legitimate reason to run something locally. (Still bad design, as it immediately makes your plugin platform and configuration dependent, but as it was only ever going to be an in-house thing, that's not too important)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was actually imagining the other way... That the action would open CMD in JIRA running on Windows (still platform-dependent nastiness) and the web browser would run an interactive session with it. Ya know, something like this:
http://jamesfriend.com.au/pce-js/ibmpc-games/
But regardless of the direction, this is both technically complicated and still a very bad idea security-wise.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah right! That makes more sense now I've re-read it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.