Results 1 to 5 of 5

Thread: Need help on Shell/ DOS

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Location
    Bangalore
    Posts
    17

    Need help on Shell/ DOS

    Hi All,

    I want to execute a command on DOS prompt with getting the file name at run time. I tried the following command, it didnt work.

    dim Shell_Command as string
    temp1 = textbox1. text
    Shell_Command = "C:\Program Files\Tip\tip -sn uc 100.077.534.772 -mp 26114 -i abc -p 123 -s " & temp1 & " -m 1 -t t1 "
    Shell(Shell_Command)

    Is there any other alternate way of adding the user input at runtime and using Shell command?

    Please help me out

    Regards,
    Anup

  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Location
    Bangalore
    Posts
    17

    Re: Need help on Shell/ DOS

    just waiting for your inputs, experts!!!

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Need help on Shell/ DOS

    if the variable for the filename can contain spaces, it must be enclosed in quotes

    to check this, debug print the string or msgbox
    the program name must also be enclosed in quotes as the path contains a space and cmmand will try to run
    c:/program ..... file not found
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Location
    Bangalore
    Posts
    17

    Re: Need help on Shell/ DOS

    Actually, I want to add the user input of a file name at run time (& temp1 &). i am putting all the executable code into the variable "Shell_Command". I want to run shell command as shell(Shell_Command). Is this possible or is there any other way to do so?


    shell("C:\Program Files\Tip\tip -sn uc 100.077.534.772 -mp 26114 -i abc -p 123 -s 1234 -m 1 -t t1 ")

    works fine for me

  5. #5
    Junior Member seba.kwiat's Avatar
    Join Date
    Jun 2009
    Posts
    30

    Re: Need help on Shell/ DOS

    This is how i do it

    you have to put quotes between long names with spaces like "Program Files" path_longName function does it.

    Code:
    Dim objShell As Object
    Set objShell = CreateObject("Wscript.Shell")
    
    Dim szScriptPath As String
    
    szScriptPath = path_longName(appDir & "\Scripts\Copy2Output.cmd")
    
    objShell.Run ("%comspec% /K " & szScriptPath & " " & szoutdir), 1, True
    
    
    
    Function path_longName(str As String) As String
    
    Dim firstPhrase, secoundPhrase As String
    Dim word As String
    Dim sztmp As String
    Dim i, j, l, k As Integer
    
    
    sztmp = str
    path_longName = sztmp
    
    firstPhrase = ""
    lastPhrase = ""
    word = ""
    
    
    ' Add "" betweent folders in the path if space exist in the folder name
    i = Len(sztmp)
    l = 3  ' For first loop entry, determine "drive letter:\"
            
    For j = 3 To i
        
        firstPhrase = Left(sztmp, l)  ' Cut 1 phrase
        
        k = i - j ' To get another letter
        secoundPhrase = Right(sztmp, k)  ' Cut 2 phrase + another k letter
            
        word = Replace(sztmp, firstPhrase, "")  ' delete 1 phrase
        word = Replace(word, secoundPhrase, "")  ' Delete 2 phrase
            
        If InStr(word, "\") Or j = Len(sztmp) Then  ' Check if folder name include "\"
            ' Delete "\"
            word = Replace(word, "\", "")
            
            ' Check if spaces exist in the world
            If InStr(word, " ") > 0 Then
                word = Chr(34) & word & Chr(34)
                
                If j = Len(sztmp) And Right(sztmp, 1) <> "\" Then
                    path_longName = firstPhrase & word & secoundPhrase
                Else
                    path_longName = firstPhrase & word & "\" & secoundPhrase
                End If
            End If
            
            l = j ' Send parameter to cut 1 phrase
        End If
    Next j
    
    
    End Function
    regards

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width