cmd Programm arbeitet nicht richtig

Status
Nicht offen für weitere Antworten.

Capasso

Bekanntes Mitglied
Hi,

erst mal ein bisschen (gekürzter) Code:
Java:
private boolean convertAndCopyAudioFile(File oldFile, String newFileName) {
		if(oldFile==null || !oldFile.exists()) {
			return false;
		}
		
		File tmpF = null;
		
		try {
			tmpF = File.createTempFile("diktat", ".wav");
			
			if(!convertGSMwithSox(oldFile.getAbsolutePath(), tmpF.getAbsolutePath())) {
				return false;
			}
				
		....
}


public static boolean convertGSMwithSox (String oldFile, String newFile){
	String soxStr = "sox \""+oldFile+"\" -U --bits 8 --channels 1 --rate 8000 \""+newFile+"\" ";
	Process p = null;
		
	try {
	    p = Runtime.getRuntime().exec("cmd /c "+soxStr);
	} catch (Exception e) {
		System.out.println(" fehler ");
		e.printStackTrace();
		return false;
	}
	
	try {
		p.waitFor();
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		System.out.println(" fehler ");
		e.printStackTrace();
		return false;
	}
	
	System.out.println(" erfolgreich "+newFile);
	return true;

}


Also, ich erstelle zuerst ein FILE objekt im temp ordner.
Anschließend verwende das Kommandozeilentool SOX zum umwandeln der Audiodateien.
Dabei wird "oldFile" umgewandelt und in "newFile" gespeichert.

Das Problem ist, dass "newFile", also die Datei im Temp-Verzeichnis immer 0 Byte große wird.

Wenn ich den Befehl "soxStr", per Hand starte (also in cmd.exe) wird die Datei im temporären Ordner angelegt.

Ich hab ehrlich gesagt momentan keinen Plan, warum es in der Anwendung nicht funktioniert.

Gruß
Capasso
 
Irgendwie nicht, aber vielleicht mach ich ja auch was falsch


es funktioniert sowohl so
Java:
String []soxArgs = {"cmd",
		"/C",
		"sox",
		"\""+oldFile+"\"",
		"-U",
		"--bits",
		"8",
		"--channels",
		"1", 
		"--rate",
		"8000",
		"\""+newFile+"\""};

also auch so:

Java:
String []soxArgs = {"cmd",
		"/C",
		"sox \""+oldFile+"\" -U --bits 8 --channels 1 --rate 8000 \""+newFile+"\""};

NICHT
 
Lies mal stdout und stderr des Prozesses aus ([c]p.getInputStream() und p.getErrorStream()[/c]) und schau Dir an, was die zu sagen haben. "geht nicht" ist in der Vielzahl aller Fälle zu ungenau.
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben