[英]Minimize Base64
所以,我在 C# 中有一個代碼,可以將圖像轉換為 base64,反之亦然。 現在,我想將生成的 base64 發送到 python。
這是我現有的代碼。
var startProcess = new ProcessStartInfo
{
FileName = pythonInterpreter,
Arguments = string.Format($"\"{pythonPathAndCode}\" {b64stringCSharp}"),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
CreateNoWindow = true,
};
using (Process process = Process.Start(startProcess))
{
error = process.StandardError.ReadToEnd();
testResult = process.StandardOutput.ReadToEnd();
lblTestOutput.Text = testResult;
lblError.Text = error;
}
當我試圖將一個小的字符串值發送到 python 時,這段代碼工作正常。但是當它發送 base64 值時,出現異常錯誤。
System.ComponentModel.Win32Exception:“文件名或擴展名太長”
請注意,當我僅發送 32,000 個或更少的字符串時,代碼運行良好,但 base64 正好包含 98,260 個。
有沒有辦法最小化這個 base64?
這是我的 python 代碼:
import sys
inputFromC = sys.stdin
print("Python Recevied: ", inputFromC)
Windows 中的命令 + arguments 的最大長度為 32767 個字符(鏈接)。 這與您所看到的一致。
我建議改為通過進程的標准輸入發送圖像。 就像是:
var startProcess = new ProcessStartInfo
{
FileName = pythonInterpreter,
Arguments = string.Format($"\"{pythonPathAndCode}\""),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
CreateNoWindow = true,
};
using (Process process = Process.Start(startProcess))
{
process.StandardInput.Write(b64stringCSharp);
process.StandardInput.Close();
error = process.StandardError.ReadToEnd();
testResult = process.StandardOutput.ReadToEnd();
lblTestOutput.Text = testResult;
lblError.Text = error;
}
顯然,修改您的 Python 腳本以從標准輸入而不是命令行參數讀取。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.