0

I have a C:\Users\Sony\Desktop\Project\Workspace\testpython\verify_fam_extended.xml:52: Execute failed: java.io.IOException: Cannot run program "python" (in directory "C:\Users\Sony\Desktop\Project\Workspace\testpython\backend\generated"): CreateProcess error=2, The system cannot find the file specified error when I run my xml code through Ant.

<exec dir="backend/generated" executable="python">
    <arg line="toplevel.py"/>
    <env key="PYTHONPATH" value="${dsltrans.install.path}:./backend/generated"/> 
</exec>
Kasun Kodagoda
  • 3,956
  • 5
  • 31
  • 54
any
  • 325
  • 5
  • 17
  • Check that your `%path%` environment variable contains the directory that `python.exe` resides in. – cdarke Apr 04 '17 at 13:47
  • @cdarke my Path value is `C:\Program Files\Java\jdk1.8.0\bin;C:\Program Files\pl\bin;C:\Python22` and my python.exe is in C:\Python22 – any Apr 04 '17 at 14:17
  • Formatted the code. – Kasun Kodagoda Apr 06 '17 at 17:30
  • https://stackoverflow.com/questions/47952935/java-io-ioexception-cannot-run-program-python-createprocess-error-2-the-sys/47953300#47953300 Only this worked for me! – zorze Jan 23 '18 at 09:45

1 Answers1

0

edit python.exe must be in a directory defined in the executable path variable PATH.

Following working example assumes the presence of C:\Python33\python.exe

<project name="demo" default="main" basedir=".">
  <property environment="env" />
  <echo>PATH is set as: ${env.PATH}</echo>

  <target name="main">
    <exec dir="backend/generated" executable="python">
      <arg line="--version"/>
    </exec>        
  </target>                                
</project>

execute in a command session

set PATH=C:\Python33;%PATH%
ant 

output

Buildfile: X:\temp\build.xml
     [echo] PATH is set as: C:\Python33;...
...
main:
     [exec] Python 3.3.0

edit Just checked. The executable can be executable="python" or executable="python.exe". So @cdarke is right the issue is that python.exe is not in PATH.

SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • I changed `python` to `python.exe` but still I have a problem. – any Apr 04 '17 at 14:20
  • The executable must be in the executable path. See the updated answer. I blindly assumed it would be the case already. – SubOptimal Apr 04 '17 at 14:22
  • my Path value is C:\Program Files\Java\jdk1.8.0\bin;C:\Program Files\pl\bin;C:\Python22 and my python.exe is in C:\Python22 – any Apr 04 '17 at 14:24
  • Does it need to I change `${dsltrans.install.path}:./backend/generated` in the above code? – any Apr 04 '17 at 14:29
  • @any I add a working example. Seems in the session you execute `ant` the path to `python.exe` is not set as expected. – SubOptimal Apr 04 '17 at 14:37
  • To clarify I use this code: https://github.com/levilucio/SyVOLT/blob/master/eclipse_integration/verify_fam_extended.xml and I changed line 6 and 73. – any Apr 04 '17 at 14:48
  • if your means of path is user environmet value, this includes C:\ProgramFiles\Python22 this is the picture https://www.photobox.co.uk/my/photo?album_id=4796488059&photo_id=21647968793 – any Apr 04 '17 at 14:58
  • I don't understand `execute in a command session` part in your post. – any Apr 04 '17 at 15:17
  • @any Click on `Windows Start button` select `run...` type `cmd.exe` click `ok` go to your project directory (the one which contains the build.xml). I have not checked the github repository. How do you call `ant` to build the project? – SubOptimal Apr 05 '17 at 06:33
  • @any I amend the `build.xml` to output the `PATH` setting when `ant` is running. – SubOptimal Apr 05 '17 at 06:41