Re: Need help on Shell/ DOS
just waiting for your inputs, experts!!!
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
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
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