【发布时间】:2021-11-02 08:13:40
【问题描述】:
我有具有输入命令的 python 脚本,即从用户那里获取输入(目录)。使用 PyInstaller 我已经生成了该脚本的 exe。现在我想通过提供输入参数从 C# 使用这个 exe。但不知何故,即使在从 C# 给出参数之后,它也没有接受并弹出 Python exe 命令提示符。
Python 代码:
def CreateCSVFile(CSVDirectory):
try:
file_path = os.path.join(CSVDirectory, 'ExportResult_Stamp.csv')
## delete only if file exists ##
if os.path.exists(file_path):
os.remove(file_path)
# Create column names as required
row = ['FileName', 'Document123','abc','xyz','zzz']
with open(file_path, 'w+') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
except Exception as e:
print(str("Exception occurs:"+ e))
strDocDir = input("Give document directory:")
#print(strDocDir)
if os.path.exists(os.path.dirname(strDocDir)):
CreateCSVFile(strDocDir)
else:
warnings.warn("Provided directory doesn't exist:" + strDocDir)
C#代码:
string strCurrentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(strCurrentPath, "\\Test\\", "CSV.exe"));
startInfo.Arguments = @"C:\Pankaj\Office\ML\Projects\Stampdocuments\DDR041";
startInfo.UseShellExecute = true;
var process = System.Diagnostics.Process.Start(startInfo);
process.WaitForExit();
请提出建议。
【问题讨论】:
-
您是否以管理员身份运行了 C# exe? (假设您在 Windows 机器上)& 当您通过 cmd 手动操作时它是否有效?
-
是的。目前我处于调试模式。还尝试从调试文件夹以管理员身份以 C# exe 运行。
-
你能通过cmd手动运行吗?
-
有没有其他方法可以解决这个问题?