Solved

Batch file execution

Posted on 2004-03-31
26
240 Views
Last Modified: 2010-04-13
i have been running a program in VB that zips a bunch of files from different locations and ftp's the resulting file to multiple ftp sites. I have the program execute a batch file which runs several txt files within the ftp protocal.

Recently win 2k was updated on the network, now the dos window will only stay alive for less then a second before it is destroyed. From what i can tell, none of the commands are run anymore (tested this using a simple net send to my own machine)

The app works fine still on XP, any ideas???

0
Comment
Question by:martynlath
  • 12
  • 10
  • +1
26 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10722877
How are you calling the batch file?
Precede it with
 CMD /C
if not already...

To test it though- precede with CMD /K (window stays open)...
0
 

Author Comment

by:martynlath
ID: 10722894
Shell (App.Path & "\ftp.bat")
0
 

Author Comment

by:martynlath
ID: 10722950
could you be more clear on where to put CMD /K or /C please?



0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723055
Try shell ("CMD /K " & App.Path & "\ftp.bat")
This should at least leave the window open so you can determine where it's failing...
Can you post ftp.bat here or is it lengthy?
0
 

Author Comment

by:martynlath
ID: 10723067
batch file example:

cd\
ftp -s:"C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript.txt"
ftp -s:"C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript2.txt"
ftp -s:"C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript3.txt"
exit

example of txt file:

open 69.93.83.218
anonymous
me@you.com
binary
cd pub
cd work
put "C:\Documents and Settings\Profile 1\Desktop\dailyupdate.zip"
bye
0
 

Author Comment

by:martynlath
ID: 10723144
the problem appears to be that the batch file is being called from a directory with a space in the name. Any ideas how to stop make the whole path into a string in vb.

Dim t As String
t = """"
Shell ("CMD /K " & t & App.Path & t & "\ftp.bat")

This does not appear to work and i am unsure of another solution
0
 

Author Comment

by:martynlath
ID: 10723159
the reason the file batch file above worked is because there is no spaces in the file name. when testing it on the win 2k machine it became evident.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723186
A couple of different ways to do it - but probably the easiest would be

Shell ("CMD /C " & chr(34) & app.path & "\ftp.bat" & chr(34))
This will enclose the string in quotes...
0
 

Author Comment

by:martynlath
ID: 10723241
that did not seem to improve the issuse.

it still stops at "C:/Program"

its trying to find the program files directory
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723280
Strange - that works for me...
Could you paste that line here - also, what does App.path resolve to?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723370
This code should generate the LFN for you...
'[BEGIN CODE]
Option Explicit

Const MAX_PATH = 206

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
   
Private Declare Function GetModuleFileName Lib "kernel32" _
    Alias "GetModuleFileNameA" (ByVal hModule As Long, _
    ByVal lpFileName As String, ByVal nSize As Long) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" _
    Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long
   
Private Declare Function GetSystemDirectory Lib "kernel32" _
    Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long

Private Declare Function GetShortPathName Lib "kernel32" _
    Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
    ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long


Private Sub Form_Load()
 Dim myHandle As Long, myResult As Long, strLFNPath As String
 strLFNPath = Space$(MAX_PATH)
 myHandle = GetModuleHandle(App.EXEName)
 myResult = GetModuleFileName(myHandle, strLFNPath, MAX_PATH)
 MsgBox strLFNPath
End Sub
'[END CODE]
0
 

Author Comment

by:martynlath
ID: 10723410
app.path = C:\program files\temp files
lfn = C:\program files\temp files\vbzip.exe
bat file = C:\program files\temp files\ftp.bat
 
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:martynlath
ID: 10723444
although it says thats the error, ive noticed that the prompt points at the correct directory. so if we can carrage return the file name part. maybe that will improve the situation?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723483
vbcrlf will do that...but I'm not certain I follow what you meant there...
The shell prompt from cmd /k brings you to the right path?
0
 

Author Comment

by:martynlath
ID: 10723500
yes. although it suggests the error is in the path. though it wont run the file name. but if you type it in manually after it runs the batch file
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723560
martynlath,
Try specifying the full path for ftp in your batch file...
Something like

%systemroot%\system32\ftp -s "C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript.txt"

0
 

Author Comment

by:martynlath
ID: 10723633
good news got it working. though CMD /C doesnt run. Any idea why?

i ran it without the app.path. as it is already in the directory by default.
easy fix for that issuse :-)

/c doesnt appear to run at all though. not even in system processes.

nearly there..
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10723673
CMD /C doesn't run?  Have you tried it just from a command line?
Do you get an error?  Probably irrelevant now though.
When you say nearly there... what's left?
0
 

Author Comment

by:martynlath
ID: 10723726
correction. it needs the app path. it will only run first time otherwise. then the path is incorrect afterwards
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10724054
So, it's still not working?  I'm a bit confused now... :(

Can you step through your code and try a debug.? of the following line:

debug.? "CMD /C " & chr(34) & app.path & "\ftp.bat" & chr(34)

Thanx.
0
 

Author Comment

by:martynlath
ID: 10725543
the APP  works correctly the first time round. but from then on the folder path cannot be changed. keeps saying internal or external command not recognised. i even tried spliting the commands up over 3 batch files

Dim d, e, f As String
d = Left$(App.Path, 2)
e = Right$(App.Path, (Len(App.Path) - 3))
f = Left$(e, (Len(e) - 8))

'8 = length of "\ftp.bat"

Shell ("CMD /K" & d & "|" & "EXIT" & "|")
Shell ("CMD /K" & "cd/" & "|" & "EXIT" & "|")
Shell ("CMD /K" & "cd/" & f & "|" & "EXIT" & "|")
Shell ("CMD /K " & d & "/" & f & "ftp.bat")

 

i need a piece of code that will get me to that file given any senario, including the prompt starting on a different drive letter. I believe my close, but not quite sure what im doing wrong.
0
 
LVL 2

Expert Comment

by:JSunn
ID: 10730332
Instead of cmd /c in scripting use %COMSPEC% /C
This is a environmental varialble for your cmd.exe file. Better to use this when the script will
be run on multiple OS types.
What is the exact path to the files you want to access?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 11486576
Hmm - I'd hate to see this one trashed after all the time put into it...
martynlath - any update?
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11656008
PAQed - no points refunded (of 125)

modulo
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now