2016-09-28 2 views
0

IronPythonを初めて使用しています。私はC#アプリケーションでそれを使用したいと思います。基本的には、IronPythonのすべてのstdoutをコピーして文字列のようなものにすることを試みています。私はこのチュートリアルに続きました - https://blogs.msdn.microsoft.com/seshadripv/2008/07/08/how-to-redirect-output-from-python-using-the-dlr-hosting-api/Pythonから出力をリダイレクトする方法

しかし、MemoryStreamオブジェクトは常に空です。

何が問題になる可能性がありますか?

+0

エラーストリームもキャッチし、エラーがないことを確認してください。 –

+0

はい。 ErrorStreamに例外があります。 '((System.IO .__ ConsoleStream)runTime.IO.ErrorStream).Length'は、型 'System.NotSupportedException' 2( 'System.IO .__ ConsoleStream)runTimeの例外をスローしました。 IO.ErrorStream).Position 'が' System.NotSupportedException 'タイプの例外をスローしました3]' runTime.IO.ErrorStream.ReadTimeout 'が' System.InvalidOperationException'4 '型の例外をスローしました' runTime.IO.ErrorStream.WriteTimeout 'throw 'System.InvalidOperationException'型の例外です。さっき気付いた。さらに、Input、OutputストリームはRead/write TimeOutExceptionをスローし続けます。 – Harpreet

答えて

0

APIスクリプトに変更があります。

C#でIronPythonのを使用するには:

1)、あなたのデモを実行して、あなたのコード変更するには)

Install-Package IronPython.StdLib 
    Install-Package IronPython 

2 Nugetパッケージをインストールします。

// ScriptRuntime runTime = ScriptRuntime.Create(); //create is not available 
    ScriptRuntime runTime = ScriptRuntime.CreateFromConfiguration(); 

3)を使用してアセンブリ:

using IronPython.Hosting; 
    using Microsoft.Scripting; 
    using Microsoft.Scripting.Hosting; 

4) App.configファイルに次の行を追加します。

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <section name="microsoft.scripting" type="Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting"/> 
    </configSections> 
    <microsoft.scripting> 
    <languages> 
    <language names="IronPython;Python;py" extensions=".py" displayName="IronPython" type="IronPython.Runtime.PythonContext, IronPython"/>  
</languages> 

私は2013対でコードをテストし、それがエラーなしで働いています。

+0

答えをありがとう。私はこれをやってみたが、それは私に例外を与える、 'System.Configuration.ConfigurationErrorsException'の未処理例外は、ScriptRuntimeを使用してSystem.Configuration.dllで発生しましたrunTime = ScriptRuntime.CreateFromConfiguration(); – Harpreet

+0

app.configにエラーがあるようです。私は、構成、レビューでサンプルコードを投稿しました:http://pasted.co/7b3aa8ca –

+0

ありがとう、それは働いている! IronPythonの練習のチュートリアルを私に紹介してください。 – Harpreet

関連する問題