Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C代码启动PUTTY脚本_C#_Unix_Putty - Fatal编程技术网

C# 用C代码启动PUTTY脚本

C# 用C代码启动PUTTY脚本,c#,unix,putty,C#,Unix,Putty,我需要编写一个C代码,使用PUTTY连接到UNIX服务器,执行一个命令,例如ls-la,然后将脚本的结果返回给C。 我怎么做 我使用Process.Start在C中运行PUTTY进程 要从Putty进程中获得结果,您需要将进程重定向到标准输出流,并在代码中使用它: var processStartInfo = new ProcessStartInfo { FileName = @"C:\PuttyLocation", Arguments = @"-

我需要编写一个C代码,使用PUTTY连接到UNIX服务器,执行一个命令,例如ls-la,然后将脚本的结果返回给C。 我怎么做


我使用Process.Start在C中运行PUTTY进程

要从Putty进程中获得结果,您需要将进程重定向到标准输出流,并在代码中使用它:

    var processStartInfo = new ProcessStartInfo
    {
        FileName = @"C:\PuttyLocation",
        Arguments = @"-ssh -b abc.txt"
        RedirectStandardOutput = true,
        UseShellExecute = false, // You have to set ShellExecute to false
        ErrorDialog = false
    };

    var process = Process.Start(processStartInfo);
    if (process == null)
    {
        return;
    }

    var reader = process.StandardOutput;
    while (!reader.EndOfStream)
    {
        // Read data..
    }

好啊如何将参数传递给PUTTY?例如,如果我想写-putty.exe-ssh-b abc.txtmgroiser@icsl9932。在ProcessStartInfo中,使用Arguments属性。编辑了我的答案,将其包括在内。好的。我的Putty位于C:\tmp\Putty.exe。我的abc.txt文件也在那里,但是如果我按照你写的那样做,而没有指定abc.txt的完整路径,它就找不到该文件。我做了var processStartInfo=新的processStartInfo{FileName=@C:\tmp\putty.exe,RedirectStandardOutput=true,UseShellExecute=false,//必须将ShellExecute设置为false ErrorDialog=false,Arguments=-ssh-m abc.txtmgroiser@icsl9932 };我将该文件放在我的bin/debug文件夹中只是为了测试。进程启动,但在进程中没有任何内容。StarndardOutput.abc.txt文件包含ls-la命令