unable to run cmd.exe in jira

anisha June 17, 2014

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

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

anisha June 17, 2014

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

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.

anisha June 17, 2014
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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

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?

anisha June 17, 2014

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

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

anisha June 17, 2014

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

Sorry, I don't understand that question.

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

crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

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)

crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2014

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

Suggest an answer

Log in or Sign up to answer