2

I am trying to find a way to call python from my UWP app. So far I have a .exe file that I have compiled from python using pyinstaller (www.pyinstaller.org/). This basically allows me to package up my python script as a standalone binary (ie: you don't need python to run it). This all works well and I can call my wrapped up python .exe via cmd.exe no problem:

$ process.exe -p "path\to\file"

$ Processing file: "path\to\file"...

$ Done.

So now I just need to call it from my UWP app - so I have added it to my application like so:

C# Project

Assets/process.exe

Frustratingly, I've not had much luck googling for answers to my problem - my attempted solutions so far have included:

  • Calling the "Assets/process.exe" directly from my app
  • Looked at "Launch an app and get results". I think this seams to be for external applications however... I certainly didn't get it going anyway.
  • Opening the cmd.exe (somehow) and calling my process.exe from there.

I'm not even sure if I'm trying to do this the correct way or not. Or if I have just not understood some of my findings. Or (fingers crossed) there is a simple solution to this I just don't know about and have somehow missed as I'm very new to UWP development and C#.

So any solutions/pointers here would be greatly appreciated thanks!!

William Tonkin-Howe
  • 317
  • 1
  • 2
  • 11

1 Answers1

0

UWP apps are 'sandboxed'; i.e. they have many security restrictions placed upon them to isolate them from the rest of Windows (like not being able to read/write to the Registry and not being able to directly access random files from the file system).

So there is no way to run an .exe (or any other executable) from your UWP app. If you have access to a StorageFile (say music, video or any other file format) then you can launch the file in the default program associated with that file type.

Aniruddha Varma
  • 1,393
  • 1
  • 19
  • 32
  • Hi Aniruddha Varma - Thanks very much for your quick response! Ok that makes sense. So do you (or anyone) know of any other way I can get my Python code and dependencies to run inside a UWP project? Eg: another file format accessible to my UWP app that I can compile my Python app to. Or am I using the wrong project type entirely? Or is what I am trying to do currently impossible and the only way around this would be to rewrite my python program entirely in c#? – William Tonkin-Howe Aug 20 '16 at 03:13
  • Also to clarify - I'm really only worried about a desktop app at this time. – William Tonkin-Howe Aug 20 '16 at 03:16
  • @WilliamTonkin-Howe You could just develop a desktop app (WPF or WinForms - which don't have any security restrictions). You can integrate python libraries (I've not tried this personally) into .NET using Iron Python (https://en.wikipedia.org/wiki/IronPython). – Aniruddha Varma Aug 20 '16 at 03:24
  • @WilliamTonkin-Howe If you want to use only UWP, it might be tough to get python code working alongside it. Please see http://stackoverflow.com/questions/33457554/use-python-alongside-c-sharp-in-windows-uwp-app – Aniruddha Varma Aug 20 '16 at 03:27