4

I am working on an application that the user may wish to automate some features of (but we don't know what at the moment) I would like to provide them some kind of scripting interface so they can play with application more freely.

To me the best scenario would be to allow them to write python scripts and use functions within the application almost as a library.

However the application would need to be running as the resulting output would be best displayed in the application itself.

So I am aiming for something similar to macros within office etc but I think it would be awesome if they could use python for this.

I am thinking it would use some sort of standard input piping. Perhaps the "macro runner" could launch the C# application and then use stdinput to communicate?

More concise detail

  1. The application is a data visualization tool
  2. It is a windows desktop application (currently it does no interaction with servers etc)
  3. I want to be able to send it scripts while the application is running
  4. I don't want to restart the application for each script
  5. Preferably you would have the choice of running one command after the other or sending a full script (Something like a command window you could send scripts to)
  6. Sending a script or even multiple scripts should be fully automatable (i.e. runnable from batch scripts/build server etc.
Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
chrispepper1989
  • 327
  • 2
  • 8
  • The best way to ensure the application is running is to make the action of invoking a macro/script part of the application's interface. Either the application contains an interpreter or it starts an external interpreter and provides a inter-process communication mechanism to communicate with the script (this could be stdin/stdout of the script). – Bart van Ingen Schenau Mar 12 '15 at 11:15
  • 5
    "A 3 minute guide to embedding IronPython in a C# application": http://www.secretgeek.net/host_ironpython. Found in 30 seconds by googling for "embed python in c# program" – Doc Brown Mar 12 '15 at 11:52
  • What is your app trying to achieve that couldn't be achieved with a RESTful web service? – pdr Mar 12 '15 at 12:47
  • @pdr I'm not sure this is even a web-hosted app... But yes, Doc's right, IronPython is almost definitely what you're looking for. – Katana314 Mar 12 '15 at 13:50
  • @DocBrown That's definitely a big piece of the puzzle (I never thought to call it "embed"!) :p. I can see how this would work from an embedded separate form sense. Is there anyway I can set it up further so that an external program could send python scripts to my application? I suppose it could send the script as an argument? whats the typical practice for going beyond that? I assume setting my app up as some kind of server? – chrispepper1989 Mar 12 '15 at 15:37
  • @Katana314: The question suggests he wants an application to which Python can send messages. Which would be a web service, even if it's not web-hosted. But the comment above suggests that he might want to send scripts to the app; in that case, I might suggest running Python, rather than embedding IronPython. Although, I've a gut feeling that Python isn't the answer either. Perhaps a DSL, perhaps in Boo. And that's why I'm looking for more information. – pdr Mar 12 '15 at 16:47
  • @chrispepper1989: you can start your application with a command line parameter containing the file name of your python script, of course. But you can also use some kind of interprocess communication, when you want to automate an already running instance of your application. There are several options, but to give you an answer, you should describe a little bit more what kind of application this is(for example: is it a desktop, a command line or a web application? Do you want to restart it for every script?) – Doc Brown Mar 12 '15 at 16:47
  • @DocBrown I am thinking inter process communication, I am going to edit the question to try and be a little less woolly, thanks everyone for their help and patience so far :) – chrispepper1989 Mar 13 '15 at 09:27
  • 1
    It isn't Python, but you could use [Clearscript](http://clearscript.codeplex.com/) to accomplish this. See also http://www.chrisumbel.com/article/scripting_ironpython_dlr and http://blogs.msdn.com/b/charlie/archive/2009/10/25/hosting-ironpython-in-a-c-4-0-program.aspx – Robert Harvey Mar 13 '15 at 14:59

0 Answers0