2015-01-29 2 views
0

에서 실행할 때 나는 다음과 같습니다 배치 파일이 실패배치 파일을 실행할 때 작동하지만, 응용 프로그램

@echo off 
REM Create the folder to put the converted files in 
md PngConverted 
REM Iterate all bitmap files 
for /r %%F in (*.bmp) do (
    REM Convert the files to PNG. Resize them so they are no bigger than 1300x1300 
    REM Also limit to 250 colors. 
    convert -resize 1300x1300 -colors 250 "%%~nF%%~xF" ".\PngConverted\%%~nF.png" 
    REM Output to the user that we completed this file. 
    echo converted %%~nF%%~xF to png 
) 

그것은 ImageMagick를 변환 및 이미지의 무리의 크기를 조정하는 데 사용합니다.

방금 ​​두 번 클릭하면 작동합니다. 오류없이 실행되고 변환 된 이미지를 출력합니다.

그러나,이 같은 콘솔 응용 프로그램에 넣어려고 :

static void Main(string[] args) 
{ 
    // Run the batch file that will convert the files. 
    ExecuteCommand("ConvertImagesInCurrentFolder.bat"); 

    // Pause so the user can see what happened. 
    Console.ReadLine(); 
} 


static void ExecuteCommand(string command) 
{ 
    int exitCode; 
    ProcessStartInfo processInfo; 
    Process process; 

    processInfo = new ProcessStartInfo("cmd.exe", "/c " + command); 
    processInfo.CreateNoWindow = true; 
    processInfo.UseShellExecute = false; 
    // *** Redirect the output *** 
    processInfo.RedirectStandardError = true; 
    processInfo.RedirectStandardOutput = true; 

    process = Process.Start(processInfo); 
    process.WaitForExit(); 

    // *** Read the streams *** 
    string output = process.StandardOutput.ReadToEnd(); 
    string error = process.StandardError.ReadToEnd(); 

    exitCode = process.ExitCode; 

    Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output)); 
    Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error)); 
    Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand"); 
    process.Close(); 
} 

그리고 오류 얻을 :에서이 작업을 실행할 때 나는이 오류를 얻을 것 왜

Invalid Parameter - 1300x1300

을 내 콘솔 응용 프로그램,하지만 명령 줄에서 실행할 때?

답변

2

또한 convert이라는 Windows CMD 명령이 있습니다. ImageMagick이 환경 변수 PATH를 통해 응용 프로그램에 실제로 액세스 할 수 있는지 확인하거나 배치 파일의 ImageMagick/convert 실행 경로를 직접 지정하십시오.

귀하의 응용 프로그램이 ImageMagick/convert 대신에 CMD convert (파일 시스템 변환)을 호출하는 것으로 의심됩니다.

+0

정확히 그랬습니다! 고맙습니다. – Vaccano

관련 문제