이 경우 "/ c"다음에 공백이 부족한 것일 수 있습니다. 명령 창에서 볼 수있는 바와 같이
var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
대신, 당신은 아마 당신의
processStartInfo
인스턴스의
Arguments
속성을 검사 더 나을 것입니다. 명령 줄 당신이 게시 사항 고려하여
편집
, 나는이 문제가 무엇인지 믿습니다. cmd 도움말에서 다음을 확인하십시오.
If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters:
If all of the following conditions are met, then quote characters on the command line are preserved:
- no /S switch
- exactly two quote characters
- no special characters between the two quote characters, where special is one of: &<>()@^|
- there are one or more whitespace characters between the the two quote characters
- the string between the two quote characters is the name of an executable file.
/c를 사용하고 있으므로 인용 부호 및 특수 문자 문제가 계속 발생합니다. commandString
전체를 따옴표로 묶어보십시오. 될 것입니다
string commandString = @"""C:\WINDOWS\Notepad.exe"" ""C:\temp.txt""";
var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
실행하는 명령 줄을 : /c "C:\WINDOWS\Notepad.exe" "C:\temp.txt"
을, 그러나 이것은 C "때문에 실패합니다
은 (수동 물론 TEMP.TXT 생성) 예를 들어이 간단한 예제를 가지고 \ TEMP.TXT "실행 파일이 아닙니다.
string commandString = @"""""C:\WINDOWS\Notepad.exe"" ""C:\temp.txt""""";
var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
의 명령 행의 결과 : /c ""C:\WINDOWS\Notepad.exe" "C:\temp.txt""
궁극적으로 테스트 파일을 메모장을 여는 따옴표의 마지막 세트 전체를 감싸는 경우
, 당신은 의도 된 결과를 볼 수 있습니다.
이것은 실제로 문제가되지만 여전히 불행하게도 작동하지 않습니다. – sooprise
사용중인 명령 및 arg에 대한 자세한 정보를 제공 할 수 있습니까? 커맨드 라인 테스트와 애플리케이션 테스트간에 다른 커맨드가 실행되는 기본 디렉토리에 문제가있을 수 있습니까? –
@sooprise : 이스케이프 문자를 사용하는 데 문제가있는 경우 문자열을 C : \ sumptin 대신'@ "C : \ sumptin"에서와 같이'@'로 시작하는 것이 좋습니다. –