Inno setup pass command line argument into #define - installation

I want to pass an argument into Inno setup and ultimately create a string which has this argument (which happens to be the year) in the middle of some text e.g. if I pass MyYear=2018 to the Inno setup command line I want to make
AppName=Some text 2018 some more text
I tried to do
#define MyAppName="Some text" {#MyYear} "some more text"
and also
#define AppName1 "Some text"
#define AppName2 "some more text"
#define MyAppName={#AppName1} {#MyYear} {#AppName2}
then in setup
AppName={#MyAppName}
but it didn't like me passing the argument into the #define part - is this not allowed?
I have ended up with something that feels rather clumsy (but works) namely creating 2 strings which are either side of the argument i want to pass in and then appending the 3 strings together...
#define AppName1 "Some text"
#define AppName2 "some more text"
then in setup
AppName={#AppName1} {#MyYear} {#AppName2}

Do it like this:
#define MyAppName AppName1 + ' ' + MyYear + ' ' + AppName2

Related

Batch script to replace a two word string containing parentheses

I have a .h document with over 10000 lines of code. It looks like this:
#define GHL_NO_OF_EVENTS_CORE_2 (512uL)
#define GHL_NO_OF_CORES (1)
#define GHL_CFG_IS_GW_SAFETY_OS (1)
I need to change the comment #define GHL_CFG_IS_GW_SAFETY_OS (1) to #define GHL_CFG_IS_GW_SAFETY_OS (0)
I have tried a lot using this command but it seems like it doesn't work because of the parentheses:
powershell -Command "(gc path-to-file\Cfg.h -encoding \"Default\") -replace 'GHL_CFG_IS_GW_SAFETY_OS (1)', 'GHL_CFG_IS_GW_SAFETY_OS (0)' | Out-File -encoding \"Default\" path-to-file\Cfg.h"
Note: I can't escape the parentheses characters with ` or ^, it just doesn't work.

How to use a preprocessor variable within a preprocessor function with Inno Setup

I try to run a PowerShell script using Exec() preprocessor function, but I need to pass two arguments to it. How can I do that? The following snippet doesn't work.
#define PSScript SourcePath + "\\UpdateJson.ps1"
#define ConfigPath SourcePath + "\\ClientConfig.json"
#expr Exec("PowerShell -NoProfile -ExecutionPolicy Bypass -File {#PSScript} {#ConfigPath} Str({#BuildNumber})")
Thanks!
Use + operator, the same way you are already using it in your PSScript and ConfigPath declarations.
Additionally, the Exec function needs the arguments separately.
Other things:
1) You should wrap the paths to double-quotes, in case they contain spaces.
2) By default, Inno Setup preprocessor does not need escaping of backslashes.
#define PSScript SourcePath + "\UpdateJson.ps1"
#define ConfigPath SourcePath + "\ClientConfig.json"
#expr Exec("PowerShell", \
"-NoProfile -ExecutionPolicy Bypass -File """ + PSScript + """ " + \
"""" + ConfigPath + """ " + Str(BuildNumber))

How to create a command line pipe? (xcode mac os x)

How to create a command line pipe? (xcode mac os x) Hello I want to
create a command line with xcode (mac os x) that had the quality of
being used in pipe after "|" .
i know that by using xargs we can pass arguments stored in stdin into
arguments.
I would like to understand how to create a pipable command line. Thank
you for your answers
For example, if we define the hand function that should receive the
arguments to execute. In a rudimentary way we will write (in C):
int main (int argc, char ** argv)
{
char buf [512] = "";
char buf1[512] = "";
int f;
and achieve some things
the first argument of the argument array, contains in any case the no
of the command line that you are creating ex: argv [0] "echo" and the
argument following the one you wish to use, 'here for echo argv [1]
"the sun shines" of course if echo is able to receive an argument
after "|" (pipe) for example: echo "the sun is shining" | echo, but
echo do not use the pipe.
For our main function, is elementarily we will check if argv [1]
contains an argument by
if (argv [1] == NULL)
> {
there we arbitrarily take the guess that argv [1] is empty. as a reminder our command line is located after a pipe "|" if our argv [1]
is empty, it will need to find an argument to continue using our
command line, for this we accept the postulate that if the command
line is placed after "|" pipe is that the output of the previous
command is not empty from where what will follow
> f = open ("/ dev / stdin", O_RDONLY);
> read (f, buf, sizeof (buf));
memcpy (buf1, buf, sizeof (buf));
now we have opened the stream "stdin" which necessarily contains the
output of the previous command, we use 2 buffers buf [512] and buf1
[512], because we can not fill argv [1], now that we have our
arguments in a buffer, one can realize the continuation of the
execution of the command, as if it were about argv [1].
In objective-c or in C simply, to give an line command the virtue to
be used ien pipeline as a result of the use of "|" after another
command line, it is necessary to redirect "stdin" towards the entry of
the command line as it was an argument ("argv"). From there by
mastering a little programming in "C", one must arrive at its ends to
make a command line create with xcode, usable after "|" .

How can interpreter detect being called from a script as opposed to command line?

As "is known", a script my-script-file which starts with
#!/path/to/interpreter -arg1 val1 -arg2 val2
is executed by exec calling /path/to/interpreter with 2(!) arguments:
-arg1 val1 -arg2 val2
my-script-file
(and not, as one might naively expect, with 5 arguments
-arg1
val1
-arg2
val2
my-script-file
as has been explained in many previous questions, e.g.,
https://stackoverflow.com/a/4304187/850781).
My problem is from the POV of an interpreter developer, not script writer.
How do I detect from inside the interpreter executable that I was called from shebang as opposed to the command line?
Then I will be able to decide whether I need to split my first argument
by space to go from "-arg1 val1 -arg2 val2" to ["-arg1", "val1", "-arg2", "val2"] or not.
The main issue here is script files named with spaces in them.
If I always split the 1st argument, I will fail like this:
$ my-interpreter "weird file name with spaces"
my-interpreter: "weird": No such file or directory
On Linux, with GNU libc or musl libc, you can use the aux-vector to distinguish the two cases.
Here is some sample code:
#define _GNU_SOURCE 1
#include <stdio.h>
#include <errno.h>
#include <sys/auxv.h>
#include <sys/stat.h>
int
main (int argc, char* argv[])
{
printf ("argv[0] = %s\n", argv[0]);
/* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
printf ("program_invocation_name = %s\n", program_invocation_name);
/* http://man7.org/linux/man-pages/man3/getauxval.3.html */
printf ("auxv[AT_EXECFN] = %s\n", (const char *) getauxval (AT_EXECFN));
/* Determine whether the last two are the same. */
struct stat statbuf1, statbuf2;
if (stat (program_invocation_name, &statbuf1) >= 0
&& stat ((const char *) getauxval (AT_EXECFN), &statbuf2) >= 0)
printf ("same? %d\n", statbuf1.st_dev == statbuf2.st_dev && statbuf1.st_ino == statbuf2.st_ino);
}
Result for a direct invocation:
$ ./a.out
argv[0] = ./a.out
program_invocation_name = ./a.out
auxv[AT_EXECFN] = ./a.out
same? 1
Result for an invocation through a script that starts with #!/home/bruno/a.out:
$ ./a.script
argv[0] = /home/bruno/a.out
program_invocation_name = /home/bruno/a.out
auxv[AT_EXECFN] = ./a.script
same? 0
This approach is, of course, highly unportable: Only Linux has the getauxv function. And there are surely cases where it does not work well.

Can't do shell script with a repeat with i from 1 to n loop

This works (prints, for example, “3 arguments”):
to run argv
do shell script "echo " & (count argv) & " arguments"
end run
This doesn't (prints only “Argument 3: three”, and not the previous two arguments):
to run argv
do shell script "echo " & (count argv) & " arguments"
repeat with i from 1 to (count argv)
do shell script "echo 'Argument " & i & ": " & (item i of argv) & "'"
end repeat
end run
In both cases, I'm running the script using osascript on Mac OS X 10.5.5. Example invocation:
osascript 'Script that takes arguments.applescript' Test argument three
I'm not redirecting the output, so I know that the script is not throwing an error.
If I add a display dialog statement above the do shell script, it throws a “no user interaction allowed” error, so I know that it is executing the loop body.
What am I doing wrong? What is it about this loop that causes osascript to not print anything?
Try this to avoid having to use the temporary file.
to run argv
set accumulator to do shell script "echo " & (count argv) & " arguments" altering line endings false
repeat with i from 1 to (count argv)
set ln to do shell script "echo 'Argument " & i & ": " & (item i of argv) & "'" altering line endings false
set accumulator to accumulator & ln
end repeat
return accumulator
end run
Your problem appears to be unrelated to the loop, or the use of argv, for that matter. Here's a much simpler test case where only the last do shell script actually returns a result:
do shell script "echo foo"
delay 2
do shell script "echo bar"
In addition, the following slight change will produce expected results:
to run argv
do shell script "echo " & (count argv) & " arguments > /test.txt"
repeat with i from 1 to (count argv)
do shell script "echo 'Argument " & i & ": " & (item i of argv) & "' >> /test.txt"
end repeat
end run
test.txt will contain four lines, like so:
3 arguments
Argument 1: foo
Argument 2: bar
Argument 3: baz
This workaround fails:
to run argv
do shell script "echo " & (count argv) & " arguments > /tmp/foo.txt"
repeat with i from 1 to (count argv)
do shell script "echo 'Argument " & i & ": " & (item i of argv) & "' >> /tmp/foo.txt"
end repeat
do shell script "cat /tmp/foo.txt"
do shell script "rm /tmp/foo.txt"
end run
Even now, only the last line is returned. This may be related to the following question of TN2065:
Q: My script will produce output over a long time. How do I read the results as they come in?
A: Again, the short answer is that you don’t — do shell script will not return until the command is done. In Unix terms, it cannot be used to create a pipe. What you can do, however, is to put the command into the background (see the next question), send its output to a file, and then read the file as it fills up.
Alas, I don't have enough AppleScript-fu to know how to have AppleScript itself read multiple lines, which I suspect would work.

Resources