简体   繁体   English

Shell命令无法从vb.net执行我的.py文件

[英]Shell command not executing my .py file from vb.net

I wonder if anyone can point me in the right direction. 我想知道是否有人可以指出我正确的方向。 I am trying to write a VB application that runs a simple python program of about 10 lines , then is supposed to return to VB and wait for the excel file that xyz.py created to read a cell from it. 我正在尝试编写一个运行大约10行的简单python程序的VB应用程序,然后应该返回VB并等待xyz.py创建的excel文件xyz.py读取一个单元格。

Problem I cannot get the file to execute. 问题我无法执行该文件。

I have tried 我努力了

 Shell("C:\Users\Clive\AppData\Local\Programs\Python\Python36\python.exe C:\Users\Clive\Documents\xyz.py") 

also: 也:

 System.Diagnostics.Process.Start("C:\Users\Clive\Documents\xyz.py") 

none of these work. 这些都不起作用。 before we carry on double clicking xyz.py gives me a correct result as well as running from the command line. 在我们双击xyz.py ,我会从命令行运行并获得正确的结果。 Am I missing a reference or something? 我是否缺少参考文献或其他内容?

thanks in advance! 提前致谢!

Clive 克莱夫

The code you are using should work fine. 您正在使用的代码应该可以正常工作。 But this worked for me 但这对我有用

Shell("py C:\fakepath\xyz.py")

If py is not in your PATH environment you can find it at C:\\Windows\\py.exe 如果py不在您的PATH环境中,则可以在C:\\ Windows \\ py.exe中找到它

It works for me. 这个对我有用。 First a python3 script to generate a csv file: 首先是一个python3脚本来生成一个csv文件:

import csv
with open('order.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile, delimiter=',')
    writer.writerow(['name', 'amount'])
    writer.writerow(['ham', '3'])
    writer.writerow(['egg', '2'])
exit(1)

Then a vb app to call the python script and read the generated csv file: 然后一个vb应用程序调用python脚本并读取生成的csv文件:

Imports System.IO
Module App
    Sub Main()
        Process.Start("C:\Projects\PythonVbInterop\PythonVbInterop\script.py").WaitForExit()
        For Each line In File.ReadAllLines("Order.csv")
            Console.WriteLine(line)
        Next
    End Sub
End Module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM