【问题标题】:WScript.Echo output command in cmdcmd中的WScript.Echo输出命令
【发布时间】:2018-08-29 20:04:26
【问题描述】:

在 CMD 中输出错误时,我需要一些帮助。

我们的时间表系统无法将假期添加到用户时间表中,这是通过脚本完成的。这是有问题的脚本部分。

    sql = "select h_user,h_date1,h_hrs,h_approved,hol_default from holidays,hol_type,logins_users where userid=h_user and h_type=hol_id and h_date1='" & today & "' order by h_type desc"
    'WScript.Echo Sql

    ar.Open Sql, cnn ', adOpenForwardOnly, adLockReadOnly, adCmdText

    If Not (ar.EOF And ar.BOF) Then  'found some holidays
        ar.movefirst()
        While Not ar.EOF
            count = count + 1
            user = ar.Fields("h_user").Value
            datestr = ar.Fields("h_date1").Value
            hours = ar.Fields("h_hrs").Value
            approved = ar.Fields("h_approved").Value
            defaulthours = ar.Fields("hol_default").Value
            If hours = 8 Then actualhours = defaulthours
            If hours = 4 Then actualhours = defaulthours / 2
            If hours = 0 Then actualhours = 0

            sqlstr = "select * from timesheets where ts_user=" & user & " and ts_hrs in(" & hours & "," & defaulthours &") and ts_date='" & today & "' and ts_job=20"
            ar1.Open sqlstr, cnn
            If Not (ar1.EOF And ar1.BOF) Then
                'record exists
                sqlstr = "update timesheets set ts_eduser=0,ts_eddate=now() where ts_user=" & user & " and ts_hrs=" & actualhours & " and ts_date='" & today & "' and ts_job=20"
            Else
                'no record
                sqlstr = "insert into timesheets (ts_user,ts_date,ts_hrs,ts_approved,ts_job,ts_cruser,ts_crdate) values (" & user & ",'" & today & "'," & actualhours & "," & approved & ",20,0,Now())"
            End If
            ar1.Close()
            cnn.Execute("insert into tracking (t_user,t_query) values (0,'" & addslashes(sqlstr) & "')")
            cnn.Execute(sqlstr)
            ar.MoveNext()
        Wend
    End If
    ar.Close
Next
message = message & count & " holidays entries added" & vbCrLf
count = 0

Set ar1 = Nothing
Set ar2 = Nothing
Set ar1 = CreateObject("ADODB.RecordSet")
Set ar2 = CreateObject("ADODB.RecordSet")

For n = 0 To 28
    daystr = DateAdd("d", n, Now())

    today = Mid(daystr, 7, 4) & "-" & Mid(daystr, 4, 2) & "-" & Left(daystr, 2)

我需要做的是专门在 cmd 窗口中输出 defaulthours 的结果,以便我检查它正在检索的数据中的错误。

我知道这是一个 WScript.Echo 命令,但我尝试了几种变体,它会阻止脚本运行。

有人能指出我正确的方向吗?

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    使用 cscript.exe 而不是默认解释器 (wscript.exe) 运行脚本。

    cscript //NoLogo C:\path\to\your.vbs
    

    cscript.exeWScript.Echo 消息打印到控制台,而不是显示消息弹出窗口。

    或者,您可以将WScript.Echo 替换为WScript.StdOut.WriteLine,这将需要cscript,否则会引发错误(因为WScript.StdOutwscript 中不可用)。

    【讨论】:

    • 您好,感谢您的回复,我正在通过命令行在 cscript 中运行脚本,目前我得到的只是以下结果,C:\JARS_auto.vbs(178, 65) Microsoft VBScript runtime错误:类型不匹配我需要实际获取该数据,因此我可以在 myphpadmin 中找到记录并删除/修改它。
    • @CarlHeath 这与您在问题中发布的问题完全不同。请将您的代码缩减为仍然会暴露问题的 minimal reproducible example,并使用该代码和代码生成的错误消息发布一个新问题。
    • 我通过在第 178 行上方添加行 wscript.echo defaulthours 找到了我正在寻找的答案,现在它输出了它试图以 2 为单位的数据。只需尝试在后端追踪记录并进行修改。
    猜你喜欢
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多