का उपयोग करते समय प्राप्त नहीं किया गया है Power.hell.exe पर पाइप इनपुट पढ़ने के लिए .NET [Console]::ReadLine()
पर कॉल करते समय मुझे डेटा हानि मिल रही है। अध्यक्ष एवं प्रबंध निदेशक में, चलाएँ:PowerShell.exe को पाइप किए गए पाठ को [कंसोल] :: रीडलाइन()
>ping localhost | powershell -NonInteractive -NoProfile -C "do {$line = [Console]::ReadLine(); ('' + (Get-Date -f 'HH:mm :ss') + $line) | Write-Host; } while ($line -ne $null)" 23:56:45time<1ms 23:56:45 23:56:46time<1ms 23:56:46 23:56:47time<1ms 23:56:47 23:56:47
Vista64 से आम तौर पर 'पिंग स्थानीय होस्ट' इस तरह दिखता है, इसलिए वहाँ ऊपर उत्पादन से लापता डेटा का एक बहुत है:
Pinging WORLNTEC02.bnysecurities.corp.local [::1] from ::1 with 32 bytes of data: Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Ping statistics for ::1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
लेकिन सी # से एक ही एपीआई का उपयोग कर प्रक्रिया में भेजे गए सभी डेटा प्राप्त करता है (कुछ न्यूलाइन मतभेदों को छोड़कर)। कोड:
namespace ConOutTime {
class Program {
static void Main (string[] args) {
string s;
while ((s = Console.ReadLine()) != null) {
if (s.Length > 0) // don't write time for empty lines
Console.WriteLine("{0:HH:mm:ss} {1}", DateTime.Now, s);
}
}
}
}
आउटपुट:
00:44:30 Pinging WORLNTEC02.bnysecurities.corp.local [::1] from ::1 with 32 bytes of data: 00:44:30 Reply from ::1: time<1ms 00:44:31 Reply from ::1: time<1ms 00:44:32 Reply from ::1: time<1ms 00:44:33 Reply from ::1: time<1ms 00:44:33 Ping statistics for ::1: 00:44:33 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), 00:44:33 Approximate round trip times in milli-seconds: 00:44:33 Minimum = 0ms, Maximum = 0ms, Average = 0ms
तो, 'खाया' हो सी # stdin के कई हिस्सों के बजाय PowerShell से एक ही एपीआई बुला सकते हैं। क्या PowerShell StdIn से स्ट्रिंग स्ट्रिंग होस्ट करता है भले ही मैंने 'PowerShell.exe -Command -' का उपयोग नहीं किया है?
मैं एक त्रुटि मिली समाप्त हो गया PowerShell के तहत इस। अपने प्रश्न फिक्सिंग सीएमडी निर्दिष्ट करने के लिए। आपके प्रश्नों अच्छा विस्तार से भरा हुआ है (धन्यवाद!), लेकिन आप एक छोटे से 'Get-Date' बिट को हटाने के द्वारा सरल बातें ahve नहीं कर सकता है? –
मुझे लगता है कि परिणामों की पुष्टि अस्थायी/अविश्वसनीय हैं। यह गति-आधारित प्रतीत होता है। यदि 'पिंग' को कुछ तेज़ी से बदल दिया गया है (' foo.txt' टाइप करें), तो मुझे कोई आउटपुट नहीं मिलता है। अगर मैं कुछ धीमा ('कॉपी कॉन') का उपयोग करता हूं तो मुझे सबकुछ मिलता है –
@JayBazuzi टाइमस्टैम्प-प्रति-लाइन एकमात्र कारण था जिसे मैं पहली जगह पावरहेल के माध्यम से पाइप कर रहा था। ;) – yzorg