unable to run cmd.exe in jira

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?

1 answer

1 accepted

1 vote
Accepted answer

You need to give the code the full path to the cmd.exe executable

I tried to give the full path... but still getting the same error!

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.

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?

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?

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.

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

is it possible to open a cmd prompt this way in a web app like jira?

Sorry, I don't understand that question.

Could you tell us what the environment looks like on the Jira you are deploying to please?

Chris Fuller Atlassian Team Jun 17, 2014

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.

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)

Chris Fuller Atlassian Team Jun 17, 2014

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.

Ah right! That makes more sense now I've re-read it!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,725 views 17 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you