问题描述
|
我好奇。如果我同时使用streamreader和streamwriter,是否有一种方法可以仅在文件X被修改后才能写入流?
可能不是以最佳方式构造此代码。它附带有帮助使我的问题更全面。
sCommand = \"whoami.exe >> C:\\Desktop\\Test.txt\"
Using swrr As New StreamWriter(File.Open(ErrorLog,FileMode.OpenOrCreate))
For Each strUserName As String In strLines
Shell(\"cmd.exe /c\" & sCommand,AppWinStyle.Hide,True,)
\'command Cannot Execute,List Why and Move onto Next Command
Using sr As New StreamReader(File.Open(Test.txt,FileMode.OpenOrCreate))
If \'\'\'??File has been modifed??\'\'\'\'\' Then swrr.WriteLine(\"PASS\") Else swrr.WriteLine(\"FAIL\")
End Using
Next
End Using
解决方法
您可以调用ѭ1来获取包含文本的字符串。
然后,您可以将新字符串与旧字符串进行比较。
读取命令输出的正确方法是将
Process
类与RedirectStandardOutput
一起使用。
然后,您可以在StandardOutput
周围创建一个StreamReader
并调用ReadToEnd()
。