首页 \ 问答 \ 进程在启动后立即停止(Process stops immediately after start)

进程在启动后立即停止(Process stops immediately after start)

希望您能够帮助我。 我正在使用MonoDevelop编写Raspberry Pi。

我想用C#执行一个python脚本并从中读取。

class Program 
{
    public static void Main(string[] args)
    {
        Process p = new Process();
        p.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
        p.StartInfo.FileName = "sudo";
        p.StartInfo.Arguments = "python gpio.py";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.Start();
        p.BeginOutputReadLine();
        p.WaitForExit();
    }

    private static void OutputHandler(Object sender, DataReceivedEventArgs args) 
    {
        Console.WriteLine(args.Data);
    }
}

在调试时我可以看到进程已退出Click for image

但是在TaskManager中我可以看到,该进程仍在运行。 脚本也控制gpio引脚。 并且脚本控制引脚(Led on / off),即使“Process has exited”也是如此。 但我从redirectOutput得到任何东西。

为什么进程在启动后立即退出(脚本有一段时间为真。它不应该停止)? 这是执行脚本的正确方法吗?
如果我从终端执行Python脚本,它可以正常工作。 它不应该是脚本的错误。 如果我启动一个进程,例如FileName“libreoffice”,它也可以。

该脚本位于“/ bin / Debug /”(文件夹)中的项目文件夹中。为任何人设置执行权限。

谢谢,
问候


Hope you can help me. I'm coding on a Raspberry Pi with MonoDevelop.

I want to execute a python script with C# and read from it.

class Program 
{
    public static void Main(string[] args)
    {
        Process p = new Process();
        p.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
        p.StartInfo.FileName = "sudo";
        p.StartInfo.Arguments = "python gpio.py";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.Start();
        p.BeginOutputReadLine();
        p.WaitForExit();
    }

    private static void OutputHandler(Object sender, DataReceivedEventArgs args) 
    {
        Console.WriteLine(args.Data);
    }
}

While Debugging i can see that the Process has exited Click for image

But in the TaskManager i can see, that the process is still running. Also the script controls the gpio pins. And the script controlls the pins (Led on/off), even if the "Process has exited" . But I dont get anything from redirectOutput.

Why does the Process immediately quits after starting (the script has a while true. it shouldn't stop)? Is this the right way to execute a script?
If I execute the Python script from the terminal, it works fine. It shouldn't be an error with the script. If I start a process e.g. FileName "libreoffice", it works too.

The script is located in the project folder in "/bin/Debug/" (the folder) Permissions for execution are set for anyone.

Thanks,
Greetings


原文:https://stackoverflow.com/questions/38594892
更新时间:2024-03-01 07:03

最满意答案

部分问题是您多次传入多值参数。 例如,表达式的一部分会导致:

...&SOURCE=A&SOURCE=B&SOURCE=C...

您只能在网址中为每个参数设置一个值。

所以解决这个问题的办法是用逗号分隔这些值并将它们作为单个字符串传入。 然后,在子报表中,您需要再次解析它们。

"&SOURCE=" & join(Parameters!SOURCE.Value,",")

您可能会遇到其他问题,例如URL长度限制,但这会解决当前的问题。


Part of the problem is that you are passing in the multi-value parameters multiple times. For example, part of your expression would result in:

...&SOURCE=A&SOURCE=B&SOURCE=C...

You can only set one value per parameter in the URL.

So the solution to that would be to comma separate the values and pass them in as a single string. Then, in the subreport, you would need to parse them out again.

"&SOURCE=" & join(Parameters!SOURCE.Value,",")

You may run into additional issues such as URL length limitations, but this will fix the immediate problem.

相关问答

更多
  • 您是否尝试过使用javascript和window.open在文本框的“转到URL”操作中打开新窗口? 例如: ="javascript:void(window.open('http://myserver/mypath/myasppage.html', '_blank'))" 看看这篇文章的更多信息。 Have you tried using javascript and window.open to open a new window in the Go To URL action of the tex ...
  • 我遇到过类似的问题。 需要明确的是,从SSRS的角度来看,这不是问题。 SSRS认为这是正确的粗略行动。 我如何解决这个问题的方法是做以下事情: 您需要修改预先填充@Unit参数的查询。 在下面的代码中,我说“@Unit Script”我引用当前运行的SQL脚本来预先填充@Unit参数。 With Unit_CTE as ( --Insert @Unit Script here ) , Count_of_Units as ( Select Count(1) as Unit_Count From ...
  • 在您调用子报告的Action中,映射到shippingIDs_sub的位置,只要数据集中的值为NULL,就使用表达式传递一些有效值。 =IIF(IsNothing(Fields!ShippingID.value),"Some Valid Value",Fields!ShippingID.value) 至于这个: 有没有办法过滤掉NULL并仅为现有ID运行子报表? 不,您无法关闭转到子报表的功能,但您可以通过更改用户点击的内容来“隐藏”它,使其看起来不像是可点击的。 例如,在我们的报告中,当某些内容可以点击 ...
  • 我假设您的第一个代码片段是您正在使用的实际代码,而不是代码的一般形式的模型。 我进一步假设你有变量叫做fprogram和cperiod 。 您需要构建查询字符串以反映您希望传递的确切值。 遗憾的是,您不能将要用作值的变量的名称编码,并插入实际值。 所以你的代码应该是这样的: // I am assuming you're getting your fprogram and cperiod values from controls. The // control names are of course u ...
  • 另一种可能的解决方案是创建一组报告。 第一份报告有一份大陆清单,其中包含下一份报告的链接,该报告有一份国家清单。 它有一个过滤器,它接受来自第一个(父)报告的参数,该报告是大陆的列表。 然后,第二个报告有另一个指向最终报告的链接,该报告接受前两个父报告的参数。 我之前在几个地方看过这种技术。 它基于钻取报告,请参阅此处以获取有关钻取报告的更多信息 。 它不如自定义网页好,但不是每个人都有友好的网站开发人员可用:-) Another possible solution is to create set of ...
  • 检查您的“报告参数”是否与您的数据集关联为“数据集参数”: Check that your "report parameters" have been associated with your dataset as "dataset parameters":
  • 部分问题是您多次传入多值参数。 例如,表达式的一部分会导致: ...&SOURCE=A&SOURCE=B&SOURCE=C... 您只能在网址中为每个参数设置一个值。 所以解决这个问题的办法是用逗号分隔这些值并将它们作为单个字符串传入。 然后,在子报表中,您需要再次解析它们。 "&SOURCE=" & join(Parameters!SOURCE.Value,",") 您可能会遇到其他问题,例如URL长度限制,但这会解决当前的问题。 Part of the problem is that you are ...
  • 只需添加其他查询字符串参数。 例如,传递参数 Date: 2009-06-01 MachineID: Machine1, Machine2, Machine3, Machine4 在名为server上名为Folder\MyReport的报告中,您可以使用以下URL: http://server/reportserver?%2fFolder%2fMyReport&rs:Command=Render&Date=2009-06-01&MachineId=Machine1&MachineId=Mac ...
  • 要执行此操作,您必须将子报表放入列表或Tablix中。 据我所知,没有简单的方法让列表或tablix迭代多值参数中的值。 它只接受数据集。 因此,我能想到的唯一解决方法是将参数拆分为数据集中的一组行,这可能但不是微不足道的SQL。 但是,如果参数的可用值来自数据集,则情况会改善:您可以将Tablix / list挂钩到数据集,并过滤未在参数中选择的项目。 编辑:通过将数据集查询构建为表达式,我发现了将多值参数扩展为数据集的一种稍微有点破解的解决方案。 假设参数@MultiParamX此表达式将创建一个查询, ...
  • 有趣的问题,我唯一能想到的是将参数数组转换为数据集中的xml,然后通过xml节点将其转换为表。 然后应该在表达式中将数据集参数(让我们称之为@par)设置为: = "" + join(Parameters!P.Value,"") + "" 然后查询数据集将是这样的: declare @parxml xml = @par Select p.query('./text()') from @parxml.nodes('/n') as T(p) 这将提供一个表,每个选定的参数值都有一 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)