我正在尝试从我的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"
对于第二个命令,请尝试以下操作:
Command2 = """Done"" *ai*.log | findstr ""writing"" | findstr """ & Text1 & """>>FOUNDBAG.txt"
最后但并非最不重要的是,对于第四条命令,请尝试以下操作:
Command4 = "findstr ""Done"" *ai*.log | findstr ""writing"" | findstr """ & Text1 & """>>FOUNDBAG.txt"
找出这些错误的一种好方法是使用Debug.Print或MsgBox显示字符串并调整引号,直到字符串正确为止。另外,请记住,字符串中带有引号和引号。字符串中的任何其他引号都需要通过加倍引号来转义。