Pb: System.Diagnostic.Process CMD.exe

G

Gab

Hello ,

I've got a problem with a little program whitcl copy a files to a remote
folder .

I'am using the System.Diagnostic. Process to copy a file from my local
machine to remote folder , but when I test this code it's doesn't work .


Process ProcessCMD2 = new Process();

ProcessCMD2.StartInfo.FileName = "CMD.exe";

ProcessCMD2.StartInfo.Arguments = "net use
\\192.168.7.6\WsAutomateMDX\test\" + "\r\n" + "@copy /B
C:\dev_Manudax\WsAutomateMDX\bin\Debug\x3Files\ETQ0903000TEST.zpl
\\192.168.7.6\WsAutomateMDX\test\ETQ0903000TEST.zpl 1>NUL: 2>NUL:"

ProcessCMD2.Start();

ProcessCMD2.Close();


But i put this command " net use \\192.168.7.6\WsAutomateMDX\test\" +
"\r\n" + "@copy /B
C:\dev_Manudax\WsAutomateMDX\bin\Debug\x3Files\ETQ0903000TEST.zpl
\\192.168.7.6\WsAutomateMDX\test\ETQ0903000TEST.zpl 1>NUL: 2>NUL:" in the
test.bat file ,It's working !



I have no exception thrown , I don't anderstand can you help me !



Thanks lot for your help .



Gab
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello ,

I've got a problem  with a little program whitcl copy a files to a remote
folder .

I'am  using the   System.Diagnostic. Process to copy a file from my local
machine to remote  folder , but  when I test  this code it's doesn't work .

Process ProcessCMD2 = new Process();

ProcessCMD2.StartInfo.FileName = "CMD.exe";

ProcessCMD2.StartInfo.Arguments = "net use
\\192.168.7.6\WsAutomateMDX\test\"  + "\r\n" + "@copy /B
C:\dev_Manudax\WsAutomateMDX\bin\Debug\x3Files\ETQ0903000TEST.zpl
\\192.168.7.6\WsAutomateMDX\test\ETQ0903000TEST.zpl  1>NUL: 2>NUL:"

ProcessCMD2.Start();

ProcessCMD2.Close();

But i put this command  " net use \\192.168.7.6\WsAutomateMDX\test\"  +
"\r\n" + "@copy /B
C:\dev_Manudax\WsAutomateMDX\bin\Debug\x3Files\ETQ0903000TEST.zpl
\\192.168.7.6\WsAutomateMDX\test\ETQ0903000TEST.zpl  1>NUL: 2>NUL:"  in the
test.bat file ,It's working !

I have no exception thrown , I don't anderstand can you help me !

Thanks lot for your help .

Gab

You can access and work with files using UNC directly from .NET, you
do not need to call cmd for that
 
J

Jeff Johnson

I've got a problem with a little program whitcl copy a files to a remote
folder .

I'am using the System.Diagnostic. Process to copy a file from my local
machine to remote folder , but when I test this code it's doesn't work
.


Process ProcessCMD2 = new Process();

ProcessCMD2.StartInfo.FileName = "CMD.exe";

ProcessCMD2.StartInfo.Arguments = "net use
\\192.168.7.6\WsAutomateMDX\test\" + "\r\n" + "@copy /B
C:\dev_Manudax\WsAutomateMDX\bin\Debug\x3Files\ETQ0903000TEST.zpl
\\192.168.7.6\WsAutomateMDX\test\ETQ0903000TEST.zpl 1>NUL: 2>NUL:"

ProcessCMD2.Start();

ProcessCMD2.Close();


But i put this command " net use \\192.168.7.6\WsAutomateMDX\test\" +
"\r\n" + "@copy /B
C:\dev_Manudax\WsAutomateMDX\bin\Debug\x3Files\ETQ0903000TEST.zpl
\\192.168.7.6\WsAutomateMDX\test\ETQ0903000TEST.zpl 1>NUL: 2>NUL:" in
the test.bat file ,It's working !



I have no exception thrown , I don't anderstand can you help me !

CMD can only execute one command at a time and you're trying to give it two.
Batch files are specifically designed for executing multiple statements, so
of course it'll work when in test.bat.

Why would you even go through the command interpreter for this? Just use
System.IO.File.Copy().
 
G

Gab

I use cmd.exe because in my example I have to copy my file to a remote
folder (it 's just a test) ,but finaly my program must copy a files to
remote printers from cmd.exe .
This is my copy.bat file (it's working)
ex:

net use \\Desk_01\ZebraS4M terre123 /USER:administrateur
@copy /B c:\test\ETQ001.zpl \\Desk_01\ZebraS4M 1>NUL: 2>NUL:
 
J

Jeff Johnson

I use cmd.exe because in my example I have to copy my file to a remote
folder (it 's just a test) ,but finaly my program must copy a files to
remote printers from cmd.exe .
This is my copy.bat file (it's working)
ex:

net use \\Desk_01\ZebraS4M terre123 /USER:administrateur
@copy /B c:\test\ETQ001.zpl \\Desk_01\ZebraS4M 1>NUL: 2>NUL:

So execute a batch file. From your description, it sounds like the file
being copied will probably change, so write the commands to a .bat file in a
temp folder and then execute that file. The syntax should be something like
this:

cmd.exe /c x:\Blah\Blah\Temp.bat

If you're wondering what the /c switch does, just open a command window and
type

cmd /?
 
T

Tim Roberts

Gab said:
I use cmd.exe because in my example I have to copy my file to a remote
folder (it 's just a test) ,but finaly my program must copy a files to
remote printers from cmd.exe .

A remote printer is just another file. There's nothing special about it.
System.IO.File.Copy will work just fine.

What do you think the "copy" command does? It just opens two files and
copies the bytes.
 

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