468,512 Members | 1,485 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Batchfile with xcopy

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
Nov 20 '05 #1
5 2736
1.
instead of
While Not (p.HasExited)
End While

use
p.WaitForExit ...
2.
what is the output of the process?

--

"I didn't think it was physically possible, but this both sucks and
blows." - Bart Simpson
"Volker Jobst" <bu****@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #2
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
"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:er**************@TK2MSFTNGP10.phx.gbl...
1.
instead of
While Not (p.HasExited)
End While

use
p.WaitForExit ...
2.
what is the output of the process?

--

"I didn't think it was physically possible, but this both sucks and
blows." - Bart Simpson
"Volker Jobst" <bu****@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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



Nov 20 '05 #3
strange...
isn't the xcopy waiting for some user input?
"Volker Jobst" <bu****@gmx.de> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
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
"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:er**************@TK2MSFTNGP10.phx.gbl...
1.
instead of
While Not (p.HasExited)
End While

use
p.WaitForExit ...
2.
what is the output of the process?

--

"I didn't think it was physically possible, but this both sucks and
blows." - Bart Simpson
"Volker Jobst" <bu****@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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



Nov 20 '05 #4
No, there can't be any waiting for input.

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

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:eg**************@TK2MSFTNGP10.phx.gbl...
strange...
isn't the xcopy waiting for some user input?
"Volker Jobst" <bu****@gmx.de> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
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
"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:er**************@TK2MSFTNGP10.phx.gbl...
1.
instead of
While Not (p.HasExited)
End While

use
p.WaitForExit ...
2.
what is the output of the process?

--

"I didn't think it was physically possible, but this both sucks and
blows." - Bart Simpson
"Volker Jobst" <bu****@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> 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
>
>



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

"Volker Jobst" <bu****@gmx.de> wrote in message
news:OS**************@TK2MSFTNGP10.phx.gbl...
No, there can't be any waiting for input.

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

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:eg**************@TK2MSFTNGP10.phx.gbl...
strange...
isn't the xcopy waiting for some user input?
"Volker Jobst" <bu****@gmx.de> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
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
"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in message news:er**************@TK2MSFTNGP10.phx.gbl...
> 1.
> instead of
> While Not (p.HasExited)
> End While
>
> use
> p.WaitForExit ...
>
>
> 2.
> what is the output of the process?
>
>
>
> --
>
> "I didn't think it was physically possible, but this both sucks and
> blows." - Bart Simpson
>
>
> "Volker Jobst" <bu****@gmx.de> wrote in message
> news:%2****************@TK2MSFTNGP12.phx.gbl...
> > 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
> >
> >
>
>



Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ryno Rijnsburger | last post: by
6 posts views Thread by Zeya | last post: by
2 posts views Thread by Bruce Schechter | last post: by
2 posts views Thread by Grigs | last post: by
1 post views Thread by lizii | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.