Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/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# 进程不在Ubuntu上工作,但在Windows上工作_C#_Asp.net Core_.net Core - Fatal编程技术网

C# 进程不在Ubuntu上工作,但在Windows上工作

C# 进程不在Ubuntu上工作,但在Windows上工作,c#,asp.net-core,.net-core,C#,Asp.net Core,.net Core,我有以下代码,可通过windows和linux的命令行运行csv导入: var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); ProcessStartInfo startInfo = null; if (isLinux) { startInfo = new ProcessStartInfo { FileName = @"/bin/bash", Arguments = $"

我有以下代码,可通过windows和linux的命令行运行csv导入:

var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
ProcessStartInfo startInfo = null;

if (isLinux)
{
    startInfo = new ProcessStartInfo
    {
        FileName = @"/bin/bash",
        Arguments = $"-c 'cat \"{filePath}\" | psql -h 127.0.0.1 -U {user} -d {dbname} -w -c \"copy data_temp from stdin csv header\"'  ",
        RedirectStandardOutput = true,
        UseShellExecute = false,
        CreateNoWindow = true,
    };

}
else
{
    startInfo = new ProcessStartInfo
    {
        FileName = @"cmd.exe",
        Arguments = $"/c cat \"{filePath}\" | psql -h 127.0.0.1 -U {user} -d {dbname} -w -c \"copy data_temp from stdin csv header\"  ",
        RedirectStandardOutput = true,
        UseShellExecute = false,
        CreateNoWindow = true,
    };
}

using (var process = new Process { StartInfo =  startInfo})
{
    process.Start();
    string result = process.StandardOutput.ReadToEnd();
    process.WaitForExit();
}
它在Windows上运行良好,但在Linux(Ubuntu18.04)上,
结果始终为空,导入不起作用

我曾尝试在终端中自己编写查询:

 /bin/bash -c 'cat "/path/file.csv" | psql -h 127.0.0.1 -U user -d user -w -c "copy data_temp from stdin csv header"'
它工作正常,但从我的代码运行时,它只返回空字符串,不导入

我做错了什么


编辑:我觉得这可能是一个权限问题。这段代码在我的asp.net核心web应用程序中,因此它将作为用户
www-data
运行
www-data
设置为nologin,因此这可能会导致问题。不确定解决方案的问题是单引号不起作用。我改成了双引号,效果很好