通过服务器中的C#代码执行批处理文件 [英] Execute a batch file through a C# code in server

查看:125
本文介绍了通过服务器中的C#代码执行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用C#应用程序将某些文件从客户端系统FTP传输到我自己的系统.由于后端是大型机PS,因此通常我在客户端系统中使用DOS命令登录,然后通过FTP传输文件.但是现在,我正在考虑通过创建一个将创建批处理文件,执行它,通过FTP传输文件然后删除该批处理文件的应用程序来使它自动化.所有过程都正常运行,但是只有一个问题,那就是巨大的问题.

当我创建批处理文件时,将成功创建该批处理文件,但是在执行该批处理文件时,它会打开.NET应用程序的另一个实例,因此无法执行.但是,如果我删除了应用程序exe文件,则批处理文件将成功运行,并且可以通过FTPies正确地进行文件操作.

但是我不明白,为什么打开应用程序的实例却在应用程序文件存在时无法运行.有什么办法可以摆脱这个?

我将exe放在客户端系统中,然后将大型机中的文件ftp传输到客户端系统中的驱动器,然后将其复制到映射的驱动器(U:\),这是我们的D盘.
批处理文件可以在没有应用程序文件的情况下正常工作.

请帮助我解决问题.

谢谢
Jashobanta

Hi,

I am trying to FTP certain files from Client system to my own system using a C# application. As the backend is a mainframe PS, so normally I use DOS commands in client systems to login and then FTP the files. But now, I am thinking of automating it a little bit by creating an application that will create a batch file, execute it, FTP the files and then delete that batch file. All processes are working properly but there is only one problem and it is HUGE.

When I create the batch files, it is created successfully, but while executing it, it opens another instance of the .NET application and thus does not execute. But if I delete the application exe file, then the batch files run successfully and FTPies the files properly.

But I am not getting, why is it opening an instance of the application and does not run when the application file is present. Is there any way to get rid of this?

I am placing the exe in the client system, and ftp the files from mainframes to a drive in client system, then copy it to a mapped drive (U:\) which is our D Drive.
The batch files work correctly without the application file.

Please help me resolve the problem.

Thanks
Jashobanta

推荐答案

你说

当我创建批处理文件时,会成功创建它,但是在执行它时,它将打开.NET应用程序的另一个实例.

我不清楚您是否正在运行批处理文件,因为除非包含命令,否则它将无法启动.NET应用程序.

没有看到任何代码很难给出答案,但是我的猜测是批处理文件与应用程序具有相同的名称,例如MyApp.exe和MyApp.bat,系统不知道您要哪个.

Process.Start("MyApp")将启动exe,但Process.Start("MyApp.bat")将执行正确的操作.

艾伦.
You say

When I create the batch files, it is created successfully, but while executing it, it opens another instance of the .NET application.

I''m not clear if you are running the batch file at all, as it would not start the .NET application unless it contained a command to do so.

Without seeing any code it''s difficult to give an answer but my guess would be that the batch file has the same name as the application, e.g. MyApp.exe and MyApp.bat, and the system doesn''t know which one you want.

Process.Start("MyApp") would start the exe but Process.Start("MyApp.bat") would do the right thing.

Alan.


行后:
sw.Write("cd U:\\jashobanta"+Environment.NewLine);



添加此行:



add this line:

sw.Write("U:" + Environment.NewLine);



希望对您有帮助!



Hope this helps!!


这篇关于通过服务器中的C#代码执行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆