Author Topic: Run external program with parameters  (Read 38 times)

LinesOfCodes

  • Newbie
  • *
  • Posts: 3
Run external program with parameters
« on: September 13, 2020, 07:01:31 AM »
Now, I'm doing a program that will convert the video file using FFmpeg.
But I want to know, What script I have to write to run FFmpeg with parameters because FFmpeg is a program that requires parameters to work properly.
And I also want to know, How can I make a file dialog to pop-up then get a path of the file that has been selected and then set the value of the input field to that path.

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 395
  • Here to help you
Re: Run external program with parameters
« Reply #1 on: September 14, 2020, 10:47:53 AM »
Hello,

Unfortunately the HN command to launch a program/file cannot send parameters to the target.

However, a work-around is to create a simple batch file with HN and then use this to launch the target with necessary parameters.

Attached is a very basic project that converts a video using FFmpeg on Windows X64 - the download link is at the bottom of this post.

The project just has one button and one field.
The location of FFmpeg is hardcoded in the script, and the final video is called Video1.mkv
The video to be converted is selected via a dialog box.

Note, the video source path has " (quotation marks) appended around it,  in case the full path contains spaces.
I didn't do this for the converted file path as it is just saved to the project directory.


Most of the code just displays information into field 1 as to aid debugging.

Also, FolderItemLaunch(fvar,1) executes the FFmpeg in the foreground to aid debugging.
Just use - FolderItemLaunch(fvar,0) to launch it in the background.

Code: [Select]
Local fname,fvar,fdetails,ftypes,fpaths,fnames,fextens
Local fhandle
 
Local sourcePath

Clear field 1

@ --- Get file ---
Put '--- Get file ---' after field 1
FileAskFilter(fname,'',fhandle,fdetails,ftypes,fpaths,fnames,fextens)
Put fname after field 1
Put line 9 of fdetails into sourcePath
Put sourcePath after field 1


@ --- Create batch file ---
Local batchname
Put ' ' after field 1
Put '--- Create batch file ---' after field 1

Put MyDirectoryFN into batchname
Append FolderSeparatorFN onto batchname
Append 'mybatch.bat' onto batchname
Put batchname after field 1
OpenTWriteAbs(batchname,fvar)


@ --- Build batch file ---
Local commandLine
Put ' ' after field 1
Put '--- Build batch file ---' after field 1
WriteTLine(fvar, 'ECHO OFF')
Put 'C:\ffmpeg-win64\bin\ffmpeg.exe -i ' into commandLine
Append '"' onto commandLine
Append sourcePath onto commandLine
Append '"' onto commandLine
Append ' -c copy ' onto commandLine
Append 'Video1.mkv ' onto commandLine
Put commandLine after field 1
WriteTLine(fvar,commandLine)
WriteTLine(fvar, 'PAUSE')
CloseTWrite(fvar)


@ --- Run batch file ---
Put ' ' after field 1
Put '--- Run batch file ---' after field 1
FolderItemGetAbs(batchname,fvar,fdetails,ftypes,fpaths,fnames,fextens)
FolderItemLaunch(fvar,1)
Put 'DONE' after field 1


 
« Last Edit: September 14, 2020, 04:44:09 PM by Malkom »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.