分析命令行参数(VBScript)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分析命令行参数(VBScript)相关的知识,希望对你有一定的参考价值。

  1. Function CmdLineParam(AStartAt, AsingleSwitch, AMatchCase, ALongSwitch, AAssigned, APosition, AFollowing)
  2.  
  3. ' AStartAt Which argument position to start at (Zero based).
  4. ' ASingleSwitch single character param char. -a -A
  5. ' AMatchCase singleSwitch should be came case for a match
  6. ' ALongSwitch Long Switch value that is preceed by --. i.e. --test --file=
  7. ' AAssigned Everything following the single switch char, or everything after = in a LongSwitch
  8. ' APosition Which value on the command line this matched
  9. ' AFollowing Value of next parameter on the command line
  10.  
  11. ' Returns true if the parameter was found
  12. Dim Found
  13. Dim c1
  14. Dim count
  15. Dim args
  16. Dim ASign
  17.  
  18. Set args = WScript.Arguments
  19.  
  20. Found = False
  21. c1 = AStartAt
  22. count = args.count
  23.  
  24. While Not found And c1 < count
  25.  
  26. If (Left(args(c1),2)) = "--" Then
  27.  
  28. If UCase(Mid(args(c1),3,Len(ALongSwitch))) = (UCase(ALongSwitch)) Then
  29. Found = True
  30. ASign = InStr(args(c1),"=")
  31.  
  32. If ASign <> 0 Then
  33. AAssigned = Mid(args(c1),ASign+1,Len(args(c1)))
  34. Else
  35. AAssigned = ""
  36. End If
  37. End If
  38.  
  39. ElseIf (Left(args(c1),1)) = "-" Then
  40. If AMatchCase = True Then
  41. ' make sure it matches
  42. If Mid(args(c1),2,1) = ASingleSwitch Then
  43. found = True
  44.  
  45. APosition = c1
  46. AAssigned = Mid(args(c1),3,Len(args(c1)))
  47. If (c1 < count+1) Then AFollowing = args(c1+1)
  48. End If
  49. Else
  50. ' we don't care about case
  51. If UCase(Mid(args(c1),2,1)) = UCase(ASingleSwitch) Then
  52. found = True
  53. APosition = c1
  54. AAssigned = Mid(args(c1),3,Len(args(c1)))
  55.  
  56. End If
  57. End If
  58. End If
  59.  
  60. AFollowing = ""
  61. If Found And (c1 < count-1) Then
  62. AFollowing = args(c1+1)
  63. End If
  64.  
  65. c1 = c1 + 1
  66. Wend
  67.  
  68. CmdLineParam = Found
  69. End Function

以上是关于分析命令行参数(VBScript)的主要内容,如果未能解决你的问题,请参考以下文章

如何以与 VBScript 相同的方式解析命令行

getopt函数(分析命令行参数)

如何在 Clang 静态分析器中污染命令行参数

CCF-命令行选项(模拟)

CSP 命令行选项(201403-3)

CCF 201403-3命令行选项 (STL模拟)