![]() |
Oberfläche für Freeware Kommandozeilen-Programm Unix2Dos
Hallo Delphianer!
Ich habe mal wieder ein Problem. Ich will eine .EXE Datei aufrufen, konkret die Datei Unix2Dos.exe, um Pascal-Quelltexte aus der Unix Welt in das DOS/Windows Format zu konvertieren. Unix: Zeile schließt mit $0A ab Dos/Windows: Zeile schließt mit $0D0A ab Ich will nun eine Oberfläche bauen, die mir in einer Listbox die zu konvertierenden Dateien anbietet. Dann wähle ich eine aus (später auch mehrere), die dann der Reihe nach konvertiert werden sollen. Mein Problem ist: Die Konvertierung klappt nicht. Warum? Von der Kommandozeile aus klappt die Konvertierung einwandfrei. Nur nicht, wenn ich das Tool von meiner Delphi-Anwendung aus aufrufe. Hier die Unit mit der Startroutine, die Unix2Dos aufruft:
Delphi-Quellcode:
Und hier das Hauptprogramm:
unit Execute;
interface uses Windows, Messages, SysUtils, Classes; type TCommandLine = type String; function ProcessExecute(CommandLine: TCommandLine; cShow: word): Integer; function ExecProcess(CommandLine,DirOfProc: TCommandLine; cShow: word): Integer; implementation uses ShellAPI; function ProcessExecute(CommandLine: TCommandLine; cShow: word): Integer; var Rslt: LongBool; StartUpInfo: TStartUpInfo; ProcessInfo: TProcessInformation; hProcess,hThread: THandle; begin FillChar(StartUpInfo, SizeOf(TStartUpInfo), 0); with StartUpInfo do begin cb := SizeOf(TStartUpInfo); dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK; wShowWindow := cShow; end; Rslt := CreateProcess( PChar(CommandLine), nil, nil, nil, false, NORMAL_PRIORITY_CLASS, nil, //Environment nil, //aktuelles Verzeichnis StartUpInfo, ProcessInfo ); if Rslt then begin WaitForInputIdle(hProcess, INFINITE); CloseHandle(hThread); CloseHandle(hProcess); Result := 0; end else Result := GetLastError; end; function ExecProcess(CommandLine,DirOfProc: TCommandLine; cShow: word): Integer; var Rslt: LongBool; StartUpInfo: TStartUpInfo; ProcessInfo: TProcessInformation; hProcess,hThread: THandle; begin FillChar(StartUpInfo, SizeOf(TStartUpInfo), 0); with StartUpInfo do begin cb := SizeOf(TStartUpInfo); dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK; wShowWindow := cShow; end; Rslt := CreateProcess( PChar(CommandLine), nil, nil, nil, false, NORMAL_PRIORITY_CLASS, nil, //Environment PChar(DirOfProc), //aktuelles Verzeichnis StartUpInfo, ProcessInfo ); if Rslt then begin WaitForInputIdle(hProcess, INFINITE); CloseHandle(hThread); CloseHandle(hProcess); Result := 0; end else Result := GetLastError; end; end.
Delphi-Quellcode:
Danke schon mal für Eure Hilfe
unit ConvMain;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, FileCtrl, StdCtrls, Execute; type TForm1 = class(TForm) btnUnixToDos: TButton; btnDosUnix: TButton; FileListBox1: TFileListBox; DirectoryListBox1: TDirectoryListBox; procedure btnUnixToDosClick(Sender: TObject); procedure btnDosUnixClick(Sender: TObject); private { Private-Deklarationen } NewInstance: THandle; public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.btnUnixToDosClick(Sender: TObject); var toConvert: String; CurrentDir, Action: String; begin //Konvertierung des Zeilenendezeichens von UNIX nach DOS CRLF CurrentDir := GetCurrentDir; if CurrentDir[Length(CurrentDir)]<>'\' then CurrentDir := CurrentDir + '\'; Action := CurrentDir + 'Unix2Dos.exe '; SetLength(CurrentDir, Length(CurrentDir)-1); toConvert := FileListBox1.Items[FileListBox1.ItemIndex]; //ShellExecInfo.lpParameters := FileListBox1.Items[FileListBox1.ItemIndex] ExecProcess( Action + toConvert, GetCurrentDir, SW_SHOWNORMAL ); end; procedure TForm1.btnDosUnixClick(Sender: TObject); begin //Konvertierung des Zeilenendezeichens von DOS nach UNIX LF ShowMessage('Diese Umwandlung konnte noch nicht implenentieirt werden! Leider'); end; end. schöni |
DP-Maintenance
Dieses Thema wurde von "alcaeus" von "Freeware" nach "Sonstige Fragen zu Delphi" verschoben.
Freeware ist nur fuer die Vorstellung von fertigen Programmen da. |
Re: Oberfläche für Freeware Kommandozeilen-Programm Unix2Dos
Warum schreibst du nicht direkt nen eigenes Tool, ist doch viel weniger Arbeit?
Delphi-Quellcode:
MfG Pr0g
procedure Unix2Win(const AFileName: String);
var fFile: TStrings; i: Integer; begin fFile := TStringList.Create; try fFile.LoadFromFile(AFileName); for i := 0 to fFile.Count - 1 do fFile[i] := StringReplace(fFile[i], #13, #10+#13, [rfReplaceAll]); fFile.SaveToFile(AFileName); finally fFile.Free; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Unix2Win('c:\test.txt'); end; |
Re: Oberfläche für Freeware Kommandozeilen-Programm Unix2Dos
Hallo PrOg!
Danke erst mal für den Tip(p). Wußte gar nich, das es so ne Funktion gibt. Aber jetzt findet Delphi nicht die richtigen Pfade.
Delphi-Quellcode:
Was mache ich falsch? Warum wird der korrekte Pfad nicht gefunden? Das Prog in das Verzeichnis kopieren, wo die Konvertierung erfolgen soll, führt leider nicht zum Erfolg.
unit main;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl; type TForm1 = class(TForm) btnQuit: TButton; btnUnix2Win: TButton; FileList: TFileListBox; DirList: TDirectoryListBox; cbx: TDriveComboBox; Label1: TLabel; Edit1: TEdit; procedure btnUnix2WinClick(Sender: TObject); procedure btnQuitClick(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure Unix2Win(const AFileName: String); var fFile: TStrings; i: Integer; begin fFile := TStringList.Create; try fFile.LoadFromFile(AFileName); for i := 0 to fFile.Count - 1 do fFile[i] := StringReplace(fFile[i], #13, #10+#13, [rfReplaceAll]); fFile.SaveToFile(AFileName); finally fFile.Free; end; end; procedure TForm1.btnUnix2WinClick(Sender: TObject); var Index: Integer; Path,Current: String; begin for Index := 0 to FileList.Items.Count-1 do begin Path := Label1.Caption; if Path[Length(Path)]<>'\' then Path := Path + '\'; if FileList.Selected[Index] then Current := FileList.Items[Index]; // ExtractFilePath(Current); // Unix2Win(Path+Current); //führt leider nicht zum Ziel. Warum? Unix2Win(ExtractFilePath(Current)); end; end; procedure TForm1.btnQuitClick(Sender: TObject); begin Application.Terminate; end; end. schöni |
Re: Oberfläche für Freeware Kommandozeilen-Programm Unix2Dos
Zitat:
Statt
Delphi-Quellcode:
kannst du auch
if Path[Length(Path)]<>'\' then Path := Path + '\';
Delphi-Quellcode:
nutzen.
Path := IncludeTrailingBackslash(Path);
Der Aufruf von
Delphi-Quellcode:
Wird nicht viel machen, denn diese Funktion liefert den geänderten Wert zurück und ändert nicht direkt den Parameter. Wenn, dann sollte ein aufruf bspw. so aussehen:
ExtractFilePath(Current);
Delphi-Quellcode:
Lass dir dochmal (bspw. mit ShowMessage()) den Pfad ausgeben, dann siehst du was falsch läuft.
Current := ExtractFilePath(Current);
Und zum Beenden kannst du auch einfach
Delphi-Quellcode:
nehmen.
Close;
|
Re: Oberfläche für Freeware Kommandozeilen-Programm Unix2Dos
Hallo PrOg!
Danke für Deine Hilfe. Problem gelöst. Ich habe allerdings in C:\ ein Unterverzeichnis angelegt, in das ich die zu konvertierenden Dateien schreibe. Dort rein kommt mein Konvertierer. Dann klappt's. Wenn ich einen zu langen Pfad habe, wie: C:\Programme\Borland\Delphi\Eigene\Projekte\Dwpl\S ource\...\<dateiname.txt >pas,inc...> dann schneidet mein Programm den Teil \Programme\Borland\Delphi\Projekte\ raus und tut so, alls ob der Pfad: C:\Dwpl\Source\...\<dateiname.<erw> wäre. Und den findet das Programm dann nicht. Wenn ich dagegen ein Verzeichnis unter C:\ bin -> aktuell: C:\Unix2Windows\, tritt das Problem nicht auf und ich kann wie gewünscht konvertieren. Zitat:
Delphi-Quellcode:
Unix2Win(Path + Current);
Zitat:
schöni |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:10 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz