Run FFMPEG command with commas and single quotes - mobile-ffmpeg

I am using FFMPEG-Kit for iOS BUT this issue applies to all releases of FFMPEG-Kit... within my command I run [1:v]format=argb,geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[withOpacitySet] but it does not work, if I run the command without that it runs fine...
Is it the commas? The quotation marks?

with not much information, I am assuming you are missing double quotes in your filter
try
"[1:v]format=argb,geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[withOpacitySet]"
if that's not the case please share your input and/or other information.

Related

Electron command line replaces single backslash with double

I'm building an app in Electron that requires a file path to be passed to it via the command line. I'm able to retrieve the command line arguments and values fine, but the backslash ('\') character keeps getting replaced with two backslashes ('\\') regardless of how I format the file path in the arguments.
For example, this is the test command: npx electron . --path='test/path\\hello\foo\/baz'
In main.js I use getSwitchValue('path') to get the value and immediately print it out:
'test/path\\\\hello\\foo\\/baz'
Notice that the forward slash stays the same, while all the backslashes are doubled.
The real problem is trying to replace the backslashes with a single backslashes or a forward slash using the string.replace method to no avail.
Obviously, I can instruct users to use forward slashes only, but when copying a file path from Windows file explorer it always uses backslashes and this the behavior expected from users.
Does anyone know why this happens and how to stop it or at least circumvent it?

Properly escape json to command line call in Ruby or Rails

I'd like to call a command line utility from a ruby script like so:
#!/env/ruby
json = {"key" => "value that \"has\" quotes"}.to_json
`aws events put-targets --cli-input-json #{json}`
Such that the resultant call should look like:
aws events put-targets --cli-input-json "{\"key\": \"value that \"has\" quotes\"}"
However, the result in this string interpolation results in a clean looking json structure without the quotes escaped and so results in error at the command line. Eg.
aws events put-targets --cli-input-json {"key": "value that \"has\" quotes"}
I need all the quotes properly escaped so that a string to the command line can be parsed as proper json.
I've tried doing string manipulation to manually escape quotes with things like:
json.gsub(/\"/,'\"')
But that doesn't work either.
This seems like it's harder than it should be. How can I render a properly escaped json string to the command line call?
I do have a rails environment that I can run this through if there are utilities that ActiveSupport provides that would facilitate this.
In this case it is simpler and more effective to make a system call without a shell. If you use the multi-argument form of Kernel#system to invoke the external command directly:
system('aws', 'events', 'puts-targets', '--cli-input-json', json)
No shell, no quoting or escaping problems with json.
If you need to do more complicated things (such as capture output or errors), look into the various methods in Open3.
If you absolutely must go through a shell there's always Shellwords.shellescape. But really, when you use the shell, you're:
Building a command line with a bunch of Ruby string operations.
Invoking a shell.
Letting the shell parse the command line (i.e. undo everything you did in (1)).
Letting the shell invoke the command with your arguments.
Why not go straight to (4) yourself?
Thanks to #mu-is-too-short, I came across Shellwords which is a neat utility. This didn't solve the problem however, but led me to search for "shell escape json" which in turn led me to: Best way to escape and unescape strings in Ruby?
So:
json = {"key" => "value that \"has\" quotes"}.to_json.dump
Properly gets the escaped string that bash will understand. Tada.
UPDATE: Don't use this in production code. You're better off following #mu-is-too-short's advice in the comments or using a higher level library.

How to execute MSBuild from Delphi?

I'm working on automating our software's build / deploy process. One major piece of this is executing msbuild to compile multiple Delphi projects.
Following numerous resources such as this one, I can do it successfully from the RAD Studio Command Line (which is simply calling rsvars.bat to set some environment variables). However, when trying to automate both this batch file and the msbuild command from Delphi, I cannot figure out how to proceed.
The key of the issue is that the batch file and the actual msbuild command are two entirely separate commands - although they need to be run together under the same environment. I found this question somewhat related, but I don't see a clear answer for my scenario.
How can I execute msbuild from Delphi while first preparing it with the environment variables as found in rsvars.bat?
As this answer showed, you can run cmd.exe itself with command-line parameters to execute commands.
Per the cmd.exe documentation:
Syntax
cmd [/c|/k] [/s] [/q] [/d] [/a|/u] [/t:{<B><F>|<F>}] [/e:{on|off}] [/f:{on|off}] [/v:{on|off}] [<String>]
Parameters
/c
Carries out the command specified by String and then stops.
...
<String>
Specifies the command you want to carry out.
...
Remarks
Using multiple commands
To use multiple commands for <String>, separate them by the command separator && and enclose them in quotation marks. For example:
"<Command>&&<Command>&&<Command>"
Processing quotation marks
If you specify /c or /k, cmd processes the remainder of String, and quotation marks are preserved only if all of the following conditions are met:
You do not use /s.
You use exactly one set of quotation marks.
You do not use any special characters within the quotation marks (for example: & < > ( ) # ^ | ).
You use one or more white-space characters within the quotation marks.
The String within quotation marks is the name of an executable file.
If the previous conditions are not met, String is processed by examining the first character to verify whether it is an opening quotation mark. If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. Any text following the closing quotation marks is preserved.
So try using CreateProcess() or ShellExecute/Ex() to run an instance of cmd.exe with these parameters:
cmd.exe /C ""<path>\rsvars.bat" && msbuild "<path>\project" <msbuild parameters> ..."
Alternatively, you can have your app load rsvars.bat and parse out the values it defines (or just define the values in your own code), and then execute msbuild using CreateProcess(), passing the desired environment variables to its lpEnvironment parameter. This way, you do not need to actually execute rsvars.bat at all.
Another way which works is to put both commands together into another new batch file. This also allows you to build multiple projects using the same environment. For example DoBuild.bat with the following contents:
call "C:\Program Files (x86)\Embarcadero\Studio\17.0\bin\rsvars.bat"
msbuild "<path>\MyProject.dproj"
msbuild "<path>\MyOtherProject.dproj"
msbuild "<path>\YetAnotherProject.dproj"
Then, just execute your batch file:
Cmd.exe /K "<path>\DoBuild.bat"

How to pass command-line args to my application when it has replaced Explorer.exe

I am using the techinque shown here and in a number of other places to cause my application to launch at start-up in place of Explorer (and Metro in Windows 8!) by creating a registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell
with c:\xxxxx\MyApp.exe as the argument.
This works fine but I also need to pass it some arguments. I've tried this by making my key value (for example) "c:\xxxx\MyApp.exe" "arg1, arg2" but it would appear that arguments are being taken as a possible second start-up program with the comma as a delimiter. Can anyone advise how to pass arguments to a shell substitute? I've also tried double quotes with the same effect. Is it actually possible to pass arguments in this way? Or must I create some kind of launcher app to do this indirectly? I really do want my app to be the only kid on the block....
BTW I'm using Windows 8.0 and my app is written in Delphi.
AFAIK, you'd use the parameters just like you would in a batch file:
"C:\xxxxx\MyApp.exe" "%1" "%2" "%3" "%4" "%5"
In a batch (or the registry) the "%x" parameters have special meaning. They always mean "parameter X".

Why won't applications in Program Files run using os.execute in lua?

I'm trying to run an executable using Lua's os.execute() function. If I do something like the following it does not work:
os.execute("C:\\\Program Files\\\Movie Maker\\\moviemk.exe")
However, if I put my lua file in the same path that moviemk.exe is in then it can call it.
Any ideas why this may be?
P.S. I'm using Windows XP SP3
This is a classic problem with the command shell. It isn't really a Windows specific problem, except that on *nix, people never really got into the habit of putting spaces in file names, and Windows puts spaces in several default system places such as C:\Program Files.
What is happening is that os.execute(str) is implemented in terms of the ANSI C function system(str), which on Windows tries to duplicate the effect of typing "cmd /C "..str to the command prompt. (On *nix, it uses /bin/sh -c instead of cmd /C.)
The classic problem is that this has to split the complete command string at whitespace to decide what program to run, and what its arguments are.
Your original example: os.execute("C:\\Program Files\\Movie Maker\\moviemk.exe") effectively became cmd /c c:\program files\movie maker\moviemk.exe, which after splitting it up on whitespace, CMD tried to find a program named c:\program to execute with arguments named files\movie and maker\moviemk.exe. This isn't what you intended.
The solution is to be much more defensive about quoting.
I would write this as:
os.execute [["C:\Program Files\Movie Maker\Moviemk.exe"]]
If there were additional command line arguments to be supplied, I would use double-quotes around each, and a single space between arguments. Using the long string syntax [[...]] has the advantage that backslash isn't a special character, so you don't need extra leaning toothpicks making it harder to read the string literal.
Using double quotes around each argument should work on both Windows and *nix, although it is harder to find commands that are the same on both platforms, of course.
One other detail to be aware of is that \Programs Files might not be on C:. There might not even be a disk named C:. (My work PC boots from E: and I find more buggy programs that way.) The easiest way to learn the correct pathname is to just use the environment variable ProgramFiles. There are many other ways.
Try:
os.execute("C:\\Program Files\\Movie Maker\\moviemk.exe")
or:
os.execute("C:/Program Files/Movie Maker/moviemk.exe")
The '\' character is used for escape characters in Lua.

Resources