一样
Shell "Dir>A:\1.txt"

解决方案 »

  1.   

    如果你只要文件名
    则要:
    Shell "Dir/B>A:\1.txt"
      

  2.   

    shell "command.com dir>a:\1.txt"
    这样才行嘛 ,因为,dir是内部命令. 
      

  3.   

    shell "command.com dir /aa >>a:\1.txt"
    '/aa是表示只显示文件 /ad表示只显示目录“>”是追加 “>>”是重新写入会擦除原有的
      

  4.   

    楼上两位都对!
    Shell "command.com dir/b>1.txt",vbHide 
    这样就不显示窗口
    同样你也可以写一个批处理,
    然后SHELL
      

  5.   

    当然了,巴顿哥。
    哈哈,我惨了,忘写一个vbHide参数了,这下分又玩完了。
    哎…现在的分真是难得呀。嘻嘻。
      

  6.   

    Shell "dir>c:\t.txt",vbHide 
      

  7.   

    呵呵,可是机器里不一定右command.com这个文件啊。所以中间右两位的方法不对。
      

  8.   

    必须写到一个 .Bat 里执行:dir >  c:\t.txt否则不能输出到 c:\t.txt
      

  9.   

    不可能没有。
    除非
    先就不说这个了,就说:
    dir的确是内部命令,就连不管是qbasic还是c它们要调用都必须这样,会有什么更好的方法调用dir呀?如果有,请告之我,因为,我也不想用command,虽然,这是很早做那些前辈们做操作系统时就固定好的。 如果有的话,嘻嘻,我以后再调用其它内部命令是就不会那么麻烦了。
      

  10.   

    有前提:就是不能用.bat因为用了.bat还叫调用内部命令吗?
      

  11.   

    '这个问题(使命令行结果输出到文本文件)就这么解决!
    '原来我调用的是 Ping > C:\out.txt
    Dim i As Long
    i = VBA.FreeFile
    Open App.Path & "\test.bat" For Output As #i
    Print #1, "DIR > " & App.Path & "\out.txt"
    Close #i
    VBA.Shell App.Path & "\test.bat"
      

  12.   

    有错重贴
    '这个问题(使命令行结果输出到文本文件)就这么解决!
      '原来我调用的是  Ping  >    C:\out.txt
      Dim  i  As  Long
      i  =  VBA.FreeFile
      Open  App.Path  &    "\test.bat"  For  Output  As  #i
      Print  #i,  "DIR  >    "  &    App.Path  &    "\out.txt"
      Close  #i
      VBA.Shell  App.Path  &    "\test.bat"
      

  13.   

    Win2k 下 是用 Cmd.exe 吧。
      

  14.   

    回复人: sonicdater(发呆呆(我答问题*不吵架*因为我呆)) (  ) 信誉:100  2002-2-27  16:05:31  得分:0  
      
    Win2k  下  是用  Cmd.exe  吧。
    我的回答:
     Shell  "command.com  dir/b>  1.txt",vbHide  
      是完全可以用的!!!!
      

  15.   

    Shell    "command.com    dir/b>      1.txt",vbHide    这样做是输出不到 1.txt的
      

  16.   

    捕获  DOS  输出  程序(  请帮忙  up) 
    =================================================================== 
    VERSION  5.00 
    Begin  VB.Form  frmDOSOutput  
          Caption                  =      "DOS  Outputs" 
          ClientHeight        =      4590 
          ClientLeft            =      60 
          ClientTop              =      345 
          ClientWidth          =      7395 
          LinkTopic              =      "Form1" 
          ScaleHeight          =      4590 
          ScaleWidth            =      7395 
          StartUpPosition  =      3    'Windows  Default 
          Begin  VB.TextBox  txtCommand  
                Height                    =      285 
                Left                        =      120 
                TabIndex                =      4 
                Top                          =      360 
                Width                      =      7095 
          End 
          Begin  VB.CommandButton  cmdExit  
                Caption                  =      "Exit" 
                Height                    =      375 
                Left                        =      5280 
                TabIndex                =      2 
                Top                          =      4080 
                Width                      =      1875 
          End 
          Begin  VB.TextBox  txtOutputs  
                BeginProperty  Font  
                      Name                        =      "Courier  New" 
                      Size                        =      8.25 
                      Charset                  =      0 
                      Weight                    =      400 
                      Underline              =      0      'False 
                      Italic                    =      0      'False 
                      Strikethrough      =      0      'False 
                EndProperty 
                ForeColor              =      &H00000000& 
                Height                    =      3135 
                Left                        =      120 
                MultiLine              =      -1    'True 
                ScrollBars            =      2    'Vertical 
                TabIndex                =      1 
                Top                          =      720 
                Width                      =      7155 
          End 
          Begin  VB.CommandButton  cmdExecute  
                Caption                  =      "Execute" 
                Default                  =      -1    'True 
                Height                    =      375 
                Left                        =      3240 
                TabIndex                =      0 
                Top                          =      4080 
                Width                      =      1875 
          End 
          Begin  VB.Label  Label1  
                AutoSize                =      -1    'True 
                Caption                  =      "Command:" 
                Height                    =      195 
                Left                        =      120 
                TabIndex                =      3 
                Top                          =      120 
                Width                      =      750 
          End 
    End 
    Attribute  VB_Name  =  "frmDOSOutput" 
    Attribute  VB_GlobalNameSpace  =  False 
    Attribute  VB_Creatable  =  False 
    Attribute  VB_PredeclaredId  =  True 
    Attribute  VB_Exposed  =  False 
    'DOSOutpus 
    'Capture  the  outputs  of  a  DOS  command 
    'Author:  Marco  Pipino 
    '[email protected] 
    '28/02/2002 
    Option  Explicit Private  WithEvents  objDOS  As  DOSOutputs 
    Attribute  objDOS.VB_VarHelpID  =  -1 Private  Sub  cmdExecute_Click() 
            On  Error  GoTo  errore 
            objDOS.CommandLine  =  txtCommand.Text 
            objDOS.ExecuteCommand 
            Exit  Sub 
    errore: 
            MsgBox  (Err.Description  &  "  -  "  &  Err.Source  &  "  -  "  &  CStr(Err.Number)) 
    End  Sub Private  Sub  cmdExit_Click() 
            Set  objDOS  =  Nothing 
            End 
    End  Sub Private  Sub  Form_Load() 
            Set  objDOS  =  New  DOSOutputs 
    End  Sub Private  Sub  objDOS_ReceiveOutputs(CommandOutputs  As  String) 
            txtOutputs.Text  =  txtOutputs.Text  &  CommandOutputs 
    End  Sub Private  Sub  txtOutputs_Change() 
            txtOutputs.SelStart  =  Len(txtOutputs.Text) 
    End  Sub 
      

  17.   

    捕获  DOS  输出  程序(  请帮忙  up) 
    =================================================================== 
    VERSION  5.00 
    Begin  VB.Form  frmDOSOutput  
          Caption                  =      "DOS  Outputs" 
          ClientHeight        =      4590 
          ClientLeft            =      60 
          ClientTop              =      345 
          ClientWidth          =      7395 
          LinkTopic              =      "Form1" 
          ScaleHeight          =      4590 
          ScaleWidth            =      7395 
          StartUpPosition  =      3    'Windows  Default 
          Begin  VB.TextBox  txtCommand  
                Height                    =      285 
                Left                        =      120 
                TabIndex                =      4 
                Top                          =      360 
                Width                      =      7095 
          End 
          Begin  VB.CommandButton  cmdExit  
                Caption                  =      "Exit" 
                Height                    =      375 
                Left                        =      5280 
                TabIndex                =      2 
                Top                          =      4080 
                Width                      =      1875 
          End 
          Begin  VB.TextBox  txtOutputs  
                BeginProperty  Font  
                      Name                        =      "Courier  New" 
                      Size                        =      8.25 
                      Charset                  =      0 
                      Weight                    =      400 
                      Underline              =      0      'False 
                      Italic                    =      0      'False 
                      Strikethrough      =      0      'False 
                EndProperty 
                ForeColor              =      &H00000000& 
                Height                    =      3135 
                Left                        =      120 
                MultiLine              =      -1    'True 
                ScrollBars            =      2    'Vertical 
                TabIndex                =      1 
                Top                          =      720 
                Width                      =      7155 
          End 
          Begin  VB.CommandButton  cmdExecute  
                Caption                  =      "Execute" 
                Default                  =      -1    'True 
                Height                    =      375 
                Left                        =      3240 
                TabIndex                =      0 
                Top                          =      4080 
                Width                      =      1875 
          End 
          Begin  VB.Label  Label1  
                AutoSize                =      -1    'True 
                Caption                  =      "Command:" 
                Height                    =      195 
                Left                        =      120 
                TabIndex                =      3 
                Top                          =      120 
                Width                      =      750 
          End 
    End 
    Attribute  VB_Name  =  "frmDOSOutput" 
    Attribute  VB_GlobalNameSpace  =  False 
    Attribute  VB_Creatable  =  False 
    Attribute  VB_PredeclaredId  =  True 
    Attribute  VB_Exposed  =  False 
    'DOSOutpus 
    'Capture  the  outputs  of  a  DOS  command 
    'Author:  Marco  Pipino 
    '[email protected] 
    '28/02/2002 
    Option  Explicit Private  WithEvents  objDOS  As  DOSOutputs 
    Attribute  objDOS.VB_VarHelpID  =  -1 Private  Sub  cmdExecute_Click() 
            On  Error  GoTo  errore 
            objDOS.CommandLine  =  txtCommand.Text 
            objDOS.ExecuteCommand 
            Exit  Sub 
    errore: 
            MsgBox  (Err.Description  &  "  -  "  &  Err.Source  &  "  -  "  &  CStr(Err.Number)) 
    End  Sub Private  Sub  cmdExit_Click() 
            Set  objDOS  =  Nothing 
            End 
    End  Sub Private  Sub  Form_Load() 
            Set  objDOS  =  New  DOSOutputs 
    End  Sub Private  Sub  objDOS_ReceiveOutputs(CommandOutputs  As  String) 
            txtOutputs.Text  =  txtOutputs.Text  &  CommandOutputs 
    End  Sub Private  Sub  txtOutputs_Change() 
            txtOutputs.SelStart  =  Len(txtOutputs.Text) 
    End  Sub 
      

  18.   

    ’.CLS 
    VERSION  1.0  CLASS 
    BEGIN 
        MultiUse  =  -1    'True 
        Persistable  =  0    'NotPersistable 
        DataBindingBehavior  =  0    'vbNone 
        DataSourceBehavior    =  0    'vbNone 
        MTSTransactionMode    =  0    'NotAnMTSObject 
    END 
    Attribute  VB_Name  =  "DOSOutputs" 
    Attribute  VB_GlobalNameSpace  =  False 
    Attribute  VB_Creatable  =  True 
    Attribute  VB_PredeclaredId  =  False 
    Attribute  VB_Exposed  =  False 
    Option  Explicit 'The  CreatePipe  function  creates  an  anonymous  pipe, 
    'and  returns  handles  to  the  read  and  write  ends  of  the  pipe. 
    Private  Declare  Function  CreatePipe  Lib  "kernel32"  (  _ 
            phReadPipe  As  Long,  _ 
            phWritePipe  As  Long,  _ 
            lpPipeAttributes  As  Any,  _ 
            ByVal  nSize  As  Long)  As  Long 
    Private  Declare  Function  ReadFile  Lib  "kernel32"  (  _ 
            ByVal  hFile  As  Long,  _ 
            ByVal  lpBuffer  As  String,  _ 
            ByVal  nNumberOfBytesToRead  As  Long,  _ 
            lpNumberOfBytesRead  As  Long,  _ 
            ByVal  lpOverlapped  As  Any)  As  Long 'Structure  used  by  the  CreateProcessA  function 
    Private  Type  SECURITY_ATTRIBUTES 
            nLength  As  Long 
            lpSecurityDescriptor  As  Long 
            bInheritHandle  As  Long 
    End  Type 'Structure  used  by  the  CreateProcessA  function 
    Private  Type  STARTUPINFO 
            cb  As  Long 
            lpReserved  As  Long 
            lpDesktop  As  Long 
            lpTitle  As  Long 
            dwX  As  Long 
            dwY  As  Long 
            dwXSize  As  Long 
            dwYSize  As  Long 
            dwXCountChars  As  Long 
            dwYCountChars  As  Long 
            dwFillAttribute  As  Long 
            dwFlags  As  Long 
            wShowWindow  As  Integer 
            cbReserved2  As  Integer 
            lpReserved2  As  Long 
            hStdInput  As  Long 
            hStdOutput  As  Long 
            hStdError  As  Long 
    End  Type 'Structure  used  by  the  CreateProcessA  function 
    Private  Type  PROCESS_INFORMATION 
            hProcess  As  Long 
            hThread  As  Long 
            dwProcessID  As  Long 
            dwThreadID  As  Long 
    End  Type 'This  function  launch  the  the  commend  and  return  the  relative  process 
    'into  the  PRECESS_INFORMATION  structure 
    Private  Declare  Function  CreateProcessA  Lib  "kernel32"  (  _ 
            ByVal  lpApplicationName  As  Long,  _ 
            ByVal  lpCommandLine  As  String,  _ 
            lpProcessAttributes  As  SECURITY_ATTRIBUTES,  _ 
            lpThreadAttributes  As  SECURITY_ATTRIBUTES,  _ 
            ByVal  bInheritHandles  As  Long,  _ 
            ByVal  dwCreationFlags  As  Long,  _ 
            ByVal  lpEnvironment  As  Long,  _ 
            ByVal  lpCurrentDirectory  As  Long,  _ 
            lpStartupInfo  As  STARTUPINFO,  _ 
            lpProcessInformation  As  PROCESS_INFORMATION)  As  Long 'Close  opened  handle 
    Private  Declare  Function  CloseHandle  Lib  "kernel32"  (  _ 
            ByVal  hHandle  As  Long)  As  Long 'Consts  for  the  above  functions 
    Private  Const  NORMAL_PRIORITY_CLASS  =  &H20& 
    Private  Const  STARTF_USESTDHANDLES  =  &H100& 
    Private  Const  STARTF_USESHOWWINDOW  =  &H1 
    Private  mCommand  As  String                    'Private  variable  for  the  CommandLine  property 
    Private  mOutputs  As  String                    'Private  variable  for  the  ReadOnly  Outputs  property 'Event  that  notify  the  temporary  buffer  to  the  object 
    Public  Event  ReceiveOutputs(CommandOutputs  As  String) 'This  property  set  and  get  the  DOS  command  line 
    'It's  possible  to  set  this  property  directly  from  the 
    'parameter  of  the  ExecuteCommand  method 
    Public  Property  Let  CommandLine(DOSCommand  As  String) 
            mCommand  =  DOSCommand 
    End  Property Public  Property  Get  CommandLine()  As  String 
            CommandLine  =  mCommand 
    End  Property 'This  property  ReadOnly  get  the  complete  output  after 
    'a  command  execution 
    Public  Property  Get  Outputs() 
            Outputs  =  mOutputs 
    End  Property Public  Function  ExecuteCommand(Optional  CommandLine  As  String)  As  String 
            Dim  proc  As  PROCESS_INFORMATION          'Process  info  filled  by  CreateProcessA 
            Dim  ret  As  Long                                          'long  variable  for  get  the  return  value  of  the 
                                                                                    'API  functions 
            Dim  start  As  STARTUPINFO                        'StartUp  Info  passed  to  the  CreateProceeeA 
                                                                                    'function 
            Dim  sa  As  SECURITY_ATTRIBUTES              'Security  Attributes  passeed  to  the 
                                                                                    'CreateProcessA  function 
            Dim  hReadPipe  As  Long                              'Read  Pipe  handle  created  by  CreatePipe 
            Dim  hWritePipe  As  Long                            'Write  Pite  handle  created  by  CreatePipe 
            Dim  lngBytesread  As  Long                        'Amount  of  byte  read  from  the  Read  Pipe  handle 
            Dim  strBuff  As  String  *  256                  'String  buffer  reading  the  Pipe         'if  the  parameter  is  not  empty  update  the  CommandLine  property 
            If  Len(CommandLine)  >  0  Then 
                    mCommand  =  CommandLine 
            End  If 
            
            'if  the  command  line  is  empty  then  exit  whit  a  error  message 
            If  Len(mCommand)  =  0  Then 
                    MsgBox  "Command  Line  empty",  vbCritical 
                    Exit  Function 
            End  If 
            
            'Create  the  Pipe 
            sa.nLength  =  Len(sa) 
            sa.bInheritHandle  =  1& 
            sa.lpSecurityDescriptor  =  0& 
            ret  =  CreatePipe(hReadPipe,  hWritePipe,  sa,  0) 
            
            If  ret  =  0  Then 
                    'If  an  error  occur  during  the  Pipe  creation  exit 
                    MsgBox  "CreatePipe  failed.  Error:  "  &  Err.LastDllError,  vbCritical 
                    Exit  Function 
            End  If 
            
            'Launch  the  command  line  application 
            start.cb  =  Len(start) 
            start.dwFlags  =  STARTF_USESTDHANDLES  Or  STARTF_USESHOWWINDOW 
            'set  the  StdOutput  and  the  StdError  output  to  the  same  Write  Pipe  handle 
            start.hStdOutput  =  hWritePipe 
            start.hStdError  =  hWritePipe 
            'Execute  the  command 
            ret&  =  CreateProcessA(0&,  mCommand,  sa,  sa,  1&,  _ 
                    NORMAL_PRIORITY_CLASS,  0&,  0&,  start,  proc) 
                    
            If  ret  <>  1  Then 
                    'if  the  command  is  not  found  .... 
                    MsgBox  "File  or  command  not  found",  vbCritical 
                    Exit  Function 
            End  If 
            
            'Now  We  can  ...  must  close  the  hWritePipe 
            ret  =  CloseHandle(hWritePipe) 
            mOutputs  =  "" 
            
            'Read  the  ReadPipe  handle 
            Do 
                    ret  =  ReadFile(hReadPipe,  strBuff,  256,  lngBytesread,  0&) 
                    mOutputs  =  mOutputs  &  Left(strBuff,  lngBytesread) 
                    'Send  data  to  the  object  via  ReceiveOutputs  event 
                    RaiseEvent  ReceiveOutputs(Left(strBuff,  lngBytesread)) 
            Loop  While  ret  <>  0 
            
            'Close  the  opened  handles 
            ret  =  CloseHandle(proc.hProcess) 
            ret  =  CloseHandle(proc.hThread) 
            ret  =  CloseHandle(hReadPipe) 
            
            'Return  the  Outputs  property  with  the  entire  DOS  output 
            ExecuteCommand  =  mOutputs 
    End  Function