cmd中的WScript.Echo输出命令

时间:2018-08-29 11:21:53

标签: vbscript

在输出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命令,但是我尝试了几种变体,并且停止了脚本的运行。

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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

相关问题