Board logo

标题: 求cscript的shell代码改进 [打印本页]

作者: wert123     时间: 2007-6-7 21:57    标题: 求cscript的shell代码改进

关于下面的脚本,大家给点建议吧,怎么改进才好
比如说,好象不能cls啊,有谁能帮我加个类似lcls清屏的功能好吗
host = WScript.FullName
hostexe = lcase(mid(host, InstrRev(host, "\")+1))
if not hostexe = "cscript.exe" Then
    set wshshell = CreateObject("WScript.Shell")
    wshshell.run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
    WScript.Quit
end If

set input = WScript.StdIn
set output = WScript.StdOut

output.Write "> "
do until input.atEndOfStream
   
    line = input.ReadLine
    if lcase(line)="exit" then
        exit do
    else
        line = Replace(line, "?", "output.WriteLine")
        ExecuteIt line
        output.Write "> "
    end if
loop
sub ExecuteIt(command)
    on error resume Next
    ExecuteGlobal command
    if not err.Number=0 Then
        output.WriteLine "Error: " & err.description
        err.clear
    end if
end sub
[ Last edited by wert123 on 2007-6-16 at 03:00 PM ]
作者: wert123     时间: 2007-6-10 11:26
有谁帮我改改啊
作者: slore     时间: 2007-6-10 12:21
这个脚本写的不错嘛。。。




那cls的时候可以输出N个空行,把显示的推上去=。=
不然重运行下脚本……

我不知道有类似cls的用法。。。。
作者: wert123     时间: 2007-6-11 11:20


  Quote:
Originally posted by slore at 2007-6-10 12:21 PM:
这个脚本写的不错嘛。。。




那cls的时候可以输出N个空行,把显示的推上去=。=
不然重运行下脚本……

我不知道有类似cls的用法。。。。

我不知道谁写的,这本书的作者我忘了啊
就是象cmd下的cls一样的效果啊,vbs是没有,只要效果一样
clx,cl123,clslore都可以的,说明白点,就是用一个操作产生一种清屏效果的方法.
作者: slore     时间: 2007-6-11 13:45
host = WScript.FullName
hostexe = LCase(Mid(host, InstrRev(host, "\") + 1))
Set wshshell = CreateObject("WScript.Shell")
If Not hostexe = "cscript.exe" Then
    wshshell.run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
    WScript.Quit
End If

Set input = WScript.StdIn
Set output = WScript.StdOut

output.Write "> "
Do Until input.atEndOfStream

    line = input.ReadLine
    If LCase(line) = "exit" Then
        Exit Do
    ElseIf LCase(line) = "cls" Then '这个是重载的……不过效果像,但是
                                          '不像CMD下可以支持之前输入的东西
        wshshell.run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
        WScript.Quit
    Else
        line = Replace(line, "?", "output.WriteLine")
        ExecuteIt line
        output.Write "> "
    End If
Loop
Sub ExecuteIt(command)
    on Error Resume Next
    ExecuteGlobal command
    If Not Err.Number = 0 Then
        output.WriteLine "Error: " & Err.description
        Err.clear
    End If
End Sub
作者: wert123     时间: 2007-6-14 20:06
非常感谢啊,不过再次运行后窗口出现在不同位置,视觉上好像感觉不够好
在该窗口中按cls后往上推30行,能帮我这样写个吗?
作者: slore     时间: 2007-6-14 20:11
有个什么blankline好象……
作者: wert123     时间: 2007-6-14 20:39


  Quote:
Originally posted by slore at 2007-6-14 08:11 PM:
有个什么blankline好象……

好象什么啊,关键时候怎么掉链子呢
作者: slore     时间: 2007-6-14 21:39
你怎么为什么不用google把链子连起来?

host = WScript.FullName
hostexe = LCase(Mid(host, InstrRev(host, "\") + 1))
Set wshshell = CreateObject("WScript.Shell")
If Not hostexe = "cscript.exe" Then
    wshshell.run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
    WScript.Quit
End If

Set input = WScript.StdIn
Set output = WScript.StdOut

output.Write "> "
Do Until input.atEndOfStream

    line = input.ReadLine
    If LCase(line) = "exit" Then
        Exit Do
    ElseIf LCase(line) = "cls" Then
        output.WriteBlankLines 30
        output.Write "> "
    Else
        line = Replace(line, "?", "output.WriteLine")
        ExecuteIt line
        output.Write "> "
    End If
Loop
Sub ExecuteIt(command)
    on Error Resume Next
    ExecuteGlobal command
    If Not Err.Number = 0 Then
        output.WriteLine "Error: " & Err.description
        Err.clear
    End If
End Sub
作者: wert123     时间: 2007-6-16 14:58
谢谢你啊,slore大师技术好,又热心,辛苦了啊!
也许要写个.dll或者.ocx文件吧,
我不会再问像这样的问题了:store你帮我写个vbs把局域网的电停了

[ Last edited by wert123 on 2007-6-16 at 03:44 PM ]