python函数运行没有结果_执行python函数将结果返回给c#

我有一个python文件,其中包含需要使用jsonrpc发布的函数.目前,我可以将函数发布到所需的站点,并在python中获得结果.但是现在我想从C#运行python脚本,获取结果并对其进行处理.我在运行python脚本并将结果返回到C#时遇到麻烦

我不想下载IronPython,因此不使用它的解决方案将有所帮助.

现在发生的事情是,有一个外壳会快速弹出,然后在按下Process.Start(start))行时消失.然后什么也没有返回给阅读器.

Python代码:

#!usr/bin/python

import sys

import json

import jsonrpclib

def dc_906(orderid, givexNum, amount):

jsonrpclib.config.use_jsonclass = True

server = jsonrpclib.Server('https://dev-dataconnect.com:50')

ping1 = server.dc_906('en', orderid, 'userid', 'password', num, amount)

print jsonrpclib.history.response #this could be a "return" instead of print, not sure.

if __name__ == "__main__":

function = sys.argv[1]

orderid = sys.argv[2]

num = sys.argv[3]

amount = sys.argv[4]

if function == 'dc_906':

dc_906(orderid, num, amount)

try

{

ProcessStartInfo start = new ProcessStartInfo();

start.FileName = @"C:\Python27\python.exe"; //full path to python.exe

//start.FileName = @"C:\Windows\system32\cmd.exe";

//start.Arguments = string.Format("{0} {1} {2} {3}", @"C:\Users\J1035\Documents\Python27\GiveX_python\test.py", "123456789", "603628982592000186162", 20.00);

start.Arguments = string.Format("{0} {1}", @"C:\Users\J1035\Documents\Python27\GiveX_python\test.py", "123456789 603628982592000186162 20.00");

start.UseShellExecute = false;

start.RedirectStandardOutput = true;

using(Process process = Process.Start(start))

using (StreamReader reader = process.StandardOutput)

{

string foo = reader.ReadToEnd();

TxtResultOutput.Text += foo;

}

}

catch (Exception ex)

{

var foo = ex.Message;

}

在命令行上运行python脚本的结果:

解决方法:

看来您忘记了参数行中的“ dc_906”.没有它,就不会调用您的函数.

标签:python,c

来源: https://codeday.me/bug/20191121/2055651.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值