Createprocess Error=2, the System Cannot Find the File Specified

CreateProcess error=2, The system cannot find the file specified

Assuming that winrar.exe is in the PATH, then Runtime.exec is capable of finding it, if it is not, you will need to supply the fully qualified path to it, for example, assuming winrar.exe is installed in C:/Program Files/WinRAR you would need to use something like...

p=r.exec("C:/Program Files/WinRAR/winrar x h:\\myjar.jar *.* h:\\new");

Personally, I would recommend that you use ProcessBuilder as it has some additional configuration abilities amongst other things. Where possible, you should also separate your command and parameters into separate String elements, it deals with things like spaces much better then a single String variable, for example...

ProcessBuilder pb = new ProcessBuilder(
"C:/Program Files/WinRAR/winrar",
"x",
"myjar.jar",
"*.*",
"new");
pb.directory(new File("H:/"));
pb. redirectErrorStream(true);

Process p = pb.start();

Don't forget to read the contents of the InputStream from the process, as failing to do so may stall the process

How to fix "CreateProcess error=2, The system cannot find the file specified" even if the Path variable is specified (crossplatform)

The reason you are getting that error on Windows is because you are not giving it the full name, including the extension. You don't have to give it the full path as long as the containing directory is in the Path variable.

You can type mvn in the Windows command interpreter (cmd.exe), and it will work because is somewhat clever about extensions. But Groovy and Java doesn't go through that.

Instead, Groovy's .execute() method delegates to Java's ProcessBuilder, which on Windows calls a native function called CreateProcess in the win32 API. In this function, if you do not specify an extension, it will assume it is a .exe file. This is why the where command work (which is actually where.exe) and git (which is actually git.exe) but not other executable types like .bat and .cmd, such as mvn.cmd.

To fix it in a way that is compatible with multiple platforms, the best option I see is to check which platform is used and alter the command accordingly. Something along these lines:

def mvnFileName = System.properties['os.name'].toLowerCase().contains('windows') ? 'mvn.cmd' : 'mvn'
def mvnbuild = "$mvnFileName package".execute() // ...

Error:java: Cannot run program CreateProcess error=2, The system cannot find the file specified

IDEA doesn't necessary use JAVA_HOME variable. The project SDK (JDK in your case) is setup in the project settings: File -> Project Structure, Project SDK and set up the proper path there.

Sample Image

CreateProcess error=2, The system cannot find the file specified [Android studio]

Since android studio is still referring to jdk1.7.0_40 change its path

  1. Goto Files->Other Settings->Default Project Structure.

  2. Under Platform Settings Select Android sdk...under JDK location change C:\Program Files (x86)\Java\jdk1.7.0_40 to C:\Program Files\Java\jdk1.7.0_45

That should do the trick :)

Error message: createProcess error=2, The system cannot find the file specified

I just fixed this by setting sdk and ndk in local.properties

For me it was adding those lines at the end of the file :

sdk.dir=C:\Users\luou\AppData\Local\Android\Sdk (It was already there)
ndk.dir=C:\Users\luou\Downloads\android-ndk-r13b-windows-x86_64\android-ndk-r13b

Maven - exec-maven-plugin - CreateProcess error=2, The system cannot find the file specified

Please try:

    <configuration>
<executable>D:\my-folder\pscp.exe</executable>
<arguments>
<argument>-r</argument>
<argument>-i</argument>
<argument>D:\my-folder-conf\user.ppk</argument>
<argument>D:\my-folder-jar\file-1.1.0.jar</argument>
<argument>ubuntu@X.XX.XX.XXX:/usr/local/folder1/jar/file-1.1.0.jar</argument>
</arguments>
</configuration>

...as documented (& shown) instead.



Related Topics



Leave a reply



Submit