473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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
Nov 20 '05 #1
20 1421
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()
///
Nov 20 '05 #2
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" <no**********@planet.nl> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
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()
///

Nov 20 '05 #3
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()
///
Nov 20 '05 #4
CT
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" <no**********@planet.nl> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
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()
///

Nov 20 '05 #5
Hi CT,

What I did send should work, it is tested.

Cor
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.

Nov 20 '05 #6
CT
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" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi CT,

What I did send should work, it is tested.

Cor
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.


Nov 20 '05 #7
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()
///
Nov 20 '05 #8
CT
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" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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()
///

Nov 20 '05 #9
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
Nov 20 '05 #10
Hi,

You can always use shell.
http://msdn.microsoft.com/library/de...vafctShell.asp

Ken
--------------------
"Henry Craven" <IU******@d.com> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #11
CT
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" <no**********@planet.nl> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #12
* "Henry Craven" <IU******@d.com> scripsit:
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.


<URL:http://dotnet.mvps.org/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #13
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" <no**********@planet.nl> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #14
Thanks Ken, been using Shell for years, but as stated, tried that and
wasn't working.

--
Henry Craven

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...
Hi,

You can always use shell.
http://msdn.microsoft.com/library/de...vafctShell.asp
Ken

Nov 20 '05 #15
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
Nov 20 '05 #16
Hi CT,

Oooogh

Maybe it is that, that "> output file" has to be not included in the
parameters

Cor
Nov 20 '05 #17
Hi Henry,

Same message as to CT

Maybe it is that, that "> output file" that has not to be included in the
parameters

Cor
Nov 20 '05 #18
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" <no**********@planet.nl> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #19
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" <IU******@d.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <no**********@planet.nl> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #20
CT
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" <no**********@planet.nl> wrote in message
news:Oc*************@tk2msftngp13.phx.gbl...
Hi CT,

Oooogh

Maybe it is that, that "> output file" has to be not included in the
parameters

Cor

Nov 20 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Bowling | last post by:
I'm creating a routine (not in a browser) to move multiple files on a daily basis to a backup directory. It can be done easily by call shell functions like 'mv file* newdir'. I can't find any...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
6
by: Lauren Wilson | last post by:
Hi folks, In an A2K app, I have attempted to use the following command in some VBA code with IDENTICAL results with every single version of the following: Shell "outlook.exe", vbHide Shell...
8
by: Mike | last post by:
Am trying to open a Microsoft Word .doc file using Access 2000 with Shell function (on Windows XP Operating system) Here is the code : Shell "C:\Program Files\Microsoft...
5
by: bearophileHUGS | last post by:
For array.array "B" means unsigned char, and such arrays accept to be initialized from (str) strings too, this is quite useful: But it seems such capability isn't shared with the append: ...
3
by: George Sakkis | last post by:
I'm trying to figure out why Popen captures the stderr of a specific command when it runs through the shell but not without it. IOW: cmd = if 1: # this captures both stdout and stderr as...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
3
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.