我可以帮忙吗?我正在尝试从我的vb6项目中运行findstr命令,但是似乎在确定正确的语法方面我过头了。我正在调用一个批处理文件来运行findstr,但是试图将其集成到项目中。任何帮助将不胜感激。谢谢,
'''''''' Lines below allow ONLY Numeric text in teh Test1 box
Dim textval As String
Dim numval As String
Private Sub Text1_Change()
textval = Text1.Text
If IsNumeric(textval) Then
numval = textval
Else
Text1.Text = CStr(numval)
End If
End Sub
'''''''' Lines above allow ONLY Numeric text in teh Test1 box
Private Sub Command1_Click()
''''Lines below enables program/project to execute in the current `enter code here`directory
Dim MyCurrentDir As String
'Show current directory
MyCurrentDir = CurDir
' MsgBox "Current Directory is " & MyCurrentDir
''''Lines above enables program/project to execute in the current directory
' Remarked for testing below WORKS: Shell (MyCurrentDir & "\findstring.bat " & Text1)
' TEST BELOW
Dim command As String
'findstr "%1" *achineCont*.log | findstr "Q_OUTFEED_EJECTBAG_SIG">FOUNDBAG.txt
command = "findstr "" & Text1 & "" *achineCont*.log | findstr ""Q_OUTFEED_EJECTBAG_SIG"">FOUNDBAG.txt"
Shell "cmd.exe /c command"
'findstr "Done" *ai*.log | findstr "writing" | findstr "%1">>FOUNDBAG.txt
Command2 = "Done"" *ai*.log | findstr ""writing"" | findstr "" & Text1 & "">>FOUNDBAG.txt"
Shell "cmd.exe /c command2"
'start "" cmd /c cscript ReadTimeFromFileWriteToNewFile.vbs
Command3 = "start """" cmd /c cscript ReadNewFile.vbs"
Shell "cmd.exe /c command3"
' TEST ABOVE
End Sub
Private Sub Command2_Click()
Unload Form1 'tell the form to unload
Set Form1 = Nothing 'free the memory used by the variables
End Sub
Private Sub Form_Load()
''''Lines below enables program/project to execute in the current directory
Dim MyCurrentDir As String
'Show current directory
MyCurrentDir = CurDir
' MsgBox "Current Directory is " & MyCurrentDir
''''Lines above enables program/project to execute in the current directory
End Sub
您只是正确的几句话。您需要像这样将其中一些增加三倍:
Command = "findstr """ & Text1 & """ *achineCont*.log | findstr ""Q_OUTFEED_EJECTBAG_SIG"">FOUNDBAG.txt"
或者至少与您提供的示例行匹配。
非常感谢Brian。您是否有任何关于此行的建议?
Command2 = "findstr """Done""" *ai*.log | findstr """writing""" | findstr """ & Text1 & "">>FOUNDBAG.txt"