Batchfile with xcopy

V

Volker Jobst

Hi.

I have this code:

Dim p As New Process
Dim info As New ProcessStartInfo
Dim sa As New ArrayList
Dim s As String
Try
With info
..FileName = "c:\test.bat"
..RedirectStandardError = True
..UseShellExecute = False
..RedirectStandardOutput = True
End With
p = Process.Start(info)
While Not (p.HasExited)
End While
sa.Add("StandardError: " & p.StandardError.ReadToEnd())
sa.Add("StandardOutput: " & p.StandardOutput.ReadToEnd())
sa.Add("ExitCode: " & p.ExitCode)
sa.Add("ExitTime: " & p.ExitTime)
sa.Add("HasExited: " & p.HasExited)
Catch ex As Exception
sa.Add("Exception: " & ex.Message)
End Try

It works great if the C:\test.bat file contains something like:
copy D:\*.* X:\

But it dows not work if the C:\test.bat file contains somthing including
xcopy like:
xcopy D:\*.* X:\

The data to transfer is not more than ~1 MB in both cases, though xcopy
copies the
sub directories too.

Could anyone please help me.

Thanx a lot.

volker
 
D

Dominique Vandensteen

1.
instead of
While Not (p.HasExited)
End While

use
p.WaitForExit ...


2.
what is the output of the process?
 
V

Volker Jobst

My problem is, that the code behind the p = Process.Start(info) never
starts.

So there is no output and I don't know where to start, but the xcopy must be
involved
because without it the batchfile and the hole program work.

If I change my code from

While Not (p.HasExited)
End While

to

WriteLine("Here1")
p.WaitForExit()
WriteLine("Here2")

there is no "Here2" on the screen, though I have been waiting long enough.
The app just hangs.

If a don't use the /e in the xcopy command, it works, excluding
subdirectories.
When I doubleclick the C:\test.bat, it works fine, even with /e.

So the orror must be in there, but I don't know where to ask.

volker
 
V

Volker Jobst

No, there can't be any waiting for input.

Thanx a lot Dominique, but I can't see a solution.
 
V

Volker Jobst

Now I'm just pipelining the output into a text file like:
xcopy D:\*.* X:\ >C:\result.txt
and it works fine now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top