Windows-10 Interface between JavaScript and Batch file executed using a Custom Protocol

38 Views Asked by At

This is a continuation of another post of mine which is not as yet fully resolved.

I'm invoking (from JavaScript using a Custom Protocol) a batch file to perform a number of possible operations (depending on the passed parameters). The Batch file receives all parameters within %1, something like:

"fdmyalbsif:%5C%20Action_1%20Append%20%5B%0A%7B%22File%22:%2220230602_101157.jpg%22,%22Type%22:%22jpg%22,%22Keys%22:%22Pepe%22%7D,%0A%7B%22File%22:%2220230602_101205.jpg%22,...

where:

  1. fdmyalbsif is the protocol name,
  2. Action_1 indicates what the batch file needs to do (there are 6 different actions),
  3. Append is an option for Action_1,
  4. The remaining string is part of a JSON array ("part" due to the limitations of batch file input length).

In order to perform whatever is requested, I first need to parse the received string into the three (sometimes 4) parts that follow fdmyalbsif. Most importantly, the JSON part must be turned into a JSON without HEXA replacements since this part is to be saved into a file (i.e. it takes few iterations to complete the whole transfer such that the first invocation creates the file while the remaining invocations append to the end of the file).

As such, I need to write replacement of %22 to ", %4B to [, %5D to ] and so forth.

I made some trials based on this page but, apparently, the presence of % in the input string sabotages things. Also tried escaping this character with another % without success.

Last, I'm aware that there are alternative implementations (VBS, compiled programs, etc.) but I'd like to attempt completing this approach before giving up.

Edit

The desired result of the manipulations would be to be able to allow acting based on the provided information after splitting the received string into:

  • Action_1
  • Append
  • The partial JSON as (this is just an example of course):
{"File":"20230602_101449.jpg","Type":"jpg","Keys":"null"},
{"File":"20230602_101540.jpg","Type":"jpg","Keys":"null"},
{"File":"20230602_103726.jpg","Type":"jpg","Keys":"null"},
{"File":"20230602_104433.mp4","Type":"mp4","Keys":"null"},
0

There are 0 best solutions below