如何在Mono C中获取shell命令的返回值#

时间:2015-04-22 15:06:42

标签: mono

我想知道如何与Mono的shell进行交互,我似乎无法找到关于此的很多信息。例如,我想返回“ls”的输出并将其粘贴到变量中 - 这是否可能?

这是我到目前为止所拥有的:

        var proc = new Process();
        proc.StartInfo.FileName = "ls";
        proc.Start ();
        proc.Close ()

1 个答案:

答案 0 :(得分:0)

可以获得shell输出。请尝试以下方法 -

// POST: api/User
        public void Post([FromBody]Person model)
        {
            const string myConnection = "Server=MYSQL5004.Smarterasp.net;Database=xxx;Uid=xxx;Pwd=xxx;";

            try
            {
                using (var connection = new SqlConnection(myConnection))
                {
                    var cmd = new SqlCommand("INSERT INTO tblUser (FirstName, LastName, Email, Username, Password) VALUES (@FirstName, @LastName, @Email, @Username, @Password)", connection)
                    {
                        CommandType = CommandType.Text,
                        Connection = connection
                    };

                    cmd.Parameters.Add("@FirstName", model.FirstName);
                    cmd.Parameters.Add("@LastName", model.LastName);
                    cmd.Parameters.Add("@Email", model.Email);
                    cmd.Parameters.Add("@Username", model.UserName);
                    cmd.Parameters.Add("@Password", model.Password);

                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                var response = e.ToString();
            }

        }