Shell() = ? in .net | | |
Try as I might I can't get the following command to execute in .net
C:\winnt\System32\xcopy.exe D:\Data\Test D:\VB /e /d /h /o /v >
C:\Copyresults.txt
How do I get it to execute in Shell() Or what would be the equivalent
..net Commands ( note: the /o is important )
Tried
Shell,
System.Diagnostics.Process,
Process.Start
Process.Startinfo ( with and without RedirectStandardInput )
At this stage I'm up the creek and don't even know what the paddle
should look like.
All help gratefully accepted.
--
Henry Craven | | | | re: Shell() = ? in .net
Hi Henry,
Two samples, the first when you call a shell extension and the second a
program
I hope this helps?
Cor
\\\
Dim p As New System.Diagnostics.ProcessStartInfo()
p.Verb = "print"
p.WindowStyle = ProcessWindowStyle.Hidden
p.FileName = "C:\filename.doc"
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)
///
\\\
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = False
p.StartInfo.Arguments = "\?"
p.StartInfo.WorkingDirectory = "C:\mydir"
p.StartInfo.FileName = "myProg.exe"
p.Start()
/// | | | | re: Shell() = ? in .net
Thanks Cor.
But I know all that. ( note the list of tried solutions )
None of it works with the example I provided.
....and I specifically need to execute, or perform that operation.
( copied from a debug.writeline output and pasted into a command window
it executes as expected.)
--
Henry Craven
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:OoSZyJlNEHA.2500@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi Henry,
>
> Two samples, the first when you call a shell extension and the second[/color]
a[color=blue]
> program
>
> I hope this helps?
>
> Cor
>
> \\\
> Dim p As New System.Diagnostics.ProcessStartInfo()
> p.Verb = "print"
> p.WindowStyle = ProcessWindowStyle.Hidden
> p.FileName = "C:\filename.doc"
> p.UseShellExecute = True
> System.Diagnostics.Process.Start(p)
> ///
> \\\
> Dim p As New Process
> p.StartInfo.UseShellExecute = False
> p.StartInfo.RedirectStandardOutput = False
> p.StartInfo.Arguments = "\?"
> p.StartInfo.WorkingDirectory = "C:\mydir"
> p.StartInfo.FileName = "myProg.exe"
> p.Start()
> ///
>
>[/color] | | | | re: Shell() = ? in .net
Hi Henry,
You can try this
I hope this one helps?
Cor
\\\
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.Arguments = "C:\Test1 C:\TestA\"
p.StartInfo.WorkingDirectory = "C:\windows\system32"
p.StartInfo.FileName = "xcopy"
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
Dim sw As New IO.StreamWriter("C:\Test2\mytest.txt")
Me.Close()
/// | | | | re: Shell() = ? in .net
The problem it seems is when you start adding the xcopy switches, in which
case it works without redirection, but with redirection no copy is
performed.
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF http://www.apress.com/book/bookDisplay.html?bID=105
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:eJCGnEmNEHA.1004@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi Henry,
>
> You can try this
>
> I hope this one helps?
>
> Cor
>
> \\\
> Dim p As New Process
> p.StartInfo.UseShellExecute = False
> p.StartInfo.RedirectStandardOutput = True
> p.StartInfo.Arguments = "C:\Test1 C:\TestA\"
> p.StartInfo.WorkingDirectory = "C:\windows\system32"
> p.StartInfo.FileName = "xcopy"
> p.Start()
> Dim sr As IO.StreamReader = p.StandardOutput
> Dim sb As New System.Text.StringBuilder("")
> Dim input As Integer = sr.Read
> Do Until input = -1
> sb.Append(ChrW(input))
> input = sr.Read
> Loop
> Dim sw As New IO.StreamWriter("C:\Test2\mytest.txt")
> Me.Close()
> ///
>
>[/color] | | | | re: Shell() = ? in .net
Hi CT,
What I did send should work, it is tested.
Cor
[color=blue]
> The problem it seems is when you start adding the xcopy switches, in which
> case it works without redirection, but with redirection no copy is
> performed.
>[/color] | | | | re: Shell() = ? in .net
Not with the switches /e /d /h /o /v (added as arguments), I'm afraid.
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF http://www.apress.com/book/bookDisplay.html?bID=105
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:%23KeYEUmNEHA.2500@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi CT,
>
> What I did send should work, it is tested.
>
> Cor
>[color=green]
> > The problem it seems is when you start adding the xcopy switches, in[/color][/color]
which[color=blue][color=green]
> > case it works without redirection, but with redirection no copy is
> > performed.
> >[/color]
>
>[/color] | | | | re: Shell() = ? in .net
Strange with me it does.
There is a little error in my sample, at the end should be
However that had only to do with the writing of the redirected file
\\\
sw.Write(sb.ToString)
sw.Close()
/// | | | | re: Shell() = ? in .net
The writing of the output is fine here, but no copying takes place. What
does your Argumnet property look like?
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF http://www.apress.com/book/bookDisplay.html?bID=105
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:%23nv1JAnNEHA.2844@tk2msftngp13.phx.gbl...[color=blue]
> Strange with me it does.
> There is a little error in my sample, at the end should be
>
> However that had only to do with the writing of the redirected file
>
> \\\
> sw.Write(sb.ToString)
> sw.Close()
> ///
>
>[/color] | | | | re: Shell() = ? in .net
Hi Carsten,
p.StartInfo.Arguments = "C:\Test1 C:\TestA\ /e /d /h /o /v "
The arguments prevent copying twice, I hope you recognized that?
Cor | | | | re: Shell() = ? in .net
Hi,
You can always use shell. http://msdn.microsoft.com/library/de...vafctShell.asp
Ken
--------------------
"Henry Craven" <IUnknown@d.com> wrote in message
news:OJsMWBlNEHA.3016@tk2msftngp13.phx.gbl...[color=blue]
> Try as I might I can't get the following command to execute in .net
>
> C:\winnt\System32\xcopy.exe D:\Data\Test D:\VB /e /d /h /o /v >
> C:\Copyresults.txt
>
> How do I get it to execute in Shell() Or what would be the equivalent
> .net Commands ( note: the /o is important )
>
> Tried
> Shell,
> System.Diagnostics.Process,
> Process.Start
> Process.Startinfo ( with and without RedirectStandardInput )
>
> At this stage I'm up the creek and don't even know what the paddle
> should look like.
>
> All help gratefully accepted.
>
> --
> Henry Craven
>
>[/color] | | | | re: Shell() = ? in .net
Not sure what goes on here, but it doesn't work. In any case, the original
poster now has an answer, so I'll work this one out myself.
Thanks
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF http://www.apress.com/book/bookDisplay.html?bID=105
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:u4k5NfnNEHA.3452@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi Carsten,
> p.StartInfo.Arguments = "C:\Test1 C:\TestA\ /e /d /h /o /v "
>
> The arguments prevent copying twice, I hope you recognized that?
>
> Cor
>
>[/color] | | | | re: Shell() = ? in .net
* "Henry Craven" <IUnknown@d.com> scripsit:[color=blue]
> Try as I might I can't get the following command to execute in .net
>
> C:\winnt\System32\xcopy.exe D:\Data\Test D:\VB /e /d /h /o /v >
> C:\Copyresults.txt
>
> How do I get it to execute in Shell() Or what would be the equivalent
> .net Commands ( note: the /o is important )
>
> Tried
> Shell,
> System.Diagnostics.Process,
> Process.Start
> Process.Startinfo ( with and without RedirectStandardInput )
>
> At this stage I'm up the creek and don't even know what the paddle
> should look like.[/color]
<URL:http://dotnet.mvps.org/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: Shell() = ? in .net
Thanks guys. nearly there.
Adding the Params and Switches to the arguments works.
However: if I include the pipe for the output it fails again.
Not sure I completely understand with the Streamreader / Stringbuilder /
streamwriter here.
the test2.txt file is showing an output of numbers which I presume are
the ASCII output for what should be the Text Log but -how- do I convert
that to a meaningful log ?
--
Henry Craven
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:u4k5NfnNEHA.3452@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi Carsten,
> p.StartInfo.Arguments = "C:\Test1 C:\TestA\ /e /d /h /o /v "
>
> The arguments prevent copying twice, I hope you recognized that?
>
> Cor
>
>[/color] | | | | re: Shell() = ? in .net
Thanks Ken, been using Shell for years, but as stated, tried that and
wasn't working.
--
Henry Craven
"Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
news:e%237xkJoNEHA.3596@tk2msftngp13.phx.gbl...[color=blue]
> Hi,
>
> You can always use shell.
>[/color] http://msdn.microsoft.com/library/de...vafctShell.asp[color=blue]
>
> Ken[/color] | | | | re: Shell() = ? in .net
Hi Henry,
Did you see the correction I did send for that on the message I made, this
should be on the end and delete that me.close.
\\\
sw.Write(sb.ToString)
sw.Close()
///
Cor | | | | re: Shell() = ? in .net
Hi CT,
Oooogh
Maybe it is that, that "> output file" has to be not included in the
parameters
Cor | | | | re: Shell() = ? in .net
Hi Henry,
Same message as to CT
Maybe it is that, that "> output file" that has not to be included in the
parameters
Cor | | | | re: Shell() = ? in .net
Thanks Cor, yes I saw it, and realised it was missing as I had it in the
version of the code I'd been trying previously to stream the Switches.
Testing also picked up the fact that it won't accept piping the result
to the text file.
changing your code to:
Dim sinput As String = sr.ReadLine()
will give me one line of readable output, but I don't know how to
capture the others so I get one line of readable, and then just numbers.
--
Henry Craven {SBS-MVP}
Melbourne Australia
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:OJthFrpNEHA.1340@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi Henry,
>
> Did you see the correction I did send for that on the message I made,[/color]
this[color=blue]
> should be on the end and delete that me.close.
> \\\
> sw.Write(sb.ToString)
> sw.Close()
> ///
> Cor[/color] | | | | re: Shell() = ? in .net
Solved: Thanks all:
Dim ProcID As Integer
Dim sSource As String = "D:\Data\Test"
Dim sDest As String = "D:\VB"
Dim sShell As String = "E:\winnt\System32\xcopy.exe"
Dim s As String = ""
'Try
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.Arguments = "D:\Data\Test D:\VB /e /d /h /o /v"
p.StartInfo.WorkingDirectory = "E:\winnt\system32"
p.StartInfo.FileName = "xcopy"
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim sinput As String = ""
Do Until sinput = "-1"
sb.Append(sr.ReadLine() & ControlChars.CrLf)
sinput = sr.Read
Loop
Dim sw As New IO.StreamWriter("C:\test2.txt")
sw.Write(sb.ToString)
Me.Close()
--
Henry Craven
"Henry Craven" <IUnknown@d.com> wrote in message
news:%23nJbz0pNEHA.1644@TK2MSFTNGP09.phx.gbl...[color=blue]
> Thanks Cor, yes I saw it, and realised it was missing as I had it in[/color]
the[color=blue]
> version of the code I'd been trying previously to stream the Switches.
>
> Testing also picked up the fact that it won't accept piping the result
> to the text file.
>
> changing your code to:
> Dim sinput As String = sr.ReadLine()
> will give me one line of readable output, but I don't know how to
> capture the others so I get one line of readable, and then just[/color]
numbers.[color=blue]
>
> --
> Henry Craven {SBS-MVP}
> Melbourne Australia
>
> "Cor Ligthert" <notfirstname@planet.nl> wrote in message
> news:OJthFrpNEHA.1340@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi Henry,
> >
> > Did you see the correction I did send for that on the message I[/color][/color]
made,[color=blue]
> this[color=green]
> > should be on the end and delete that me.close.
> > \\\
> > sw.Write(sb.ToString)
> > sw.Close()
> > ///
> > Cor[/color]
>
>
>[/color] | | | | re: Shell() = ? in .net
Nah, I removed that already.
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF http://www.apress.com/book/bookDisplay.html?bID=105
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:OcAygspNEHA.808@tk2msftngp13.phx.gbl...[color=blue]
> Hi CT,
>
> Oooogh
>
> Maybe it is that, that "> output file" has to be not included in the
> parameters
>
> Cor
>
>[/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|