Inno Setup appcmd output to file [duplicate] - iis

This question already has answers here:
How does output redirection work in Inno Setup?
(2 answers)
How to get an output of an Exec'ed program in Inno Setup?
(2 answers)
Closed 4 years ago.
I've been trying for hours to execute the following Inno Script code.
Exec('C:\Windows\System32\inetsrv\appcmd.exe', 'list site > "c:\test\temp.txt"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
It executes the appcmd program whose output is saved in a file.
The above code doesn't stream the output into a file when run from Inno Script. When I run the code from command line, it works fine. I can also execute the other commands like ipconfig and redirect the output to the file.
I've also tried the following code but to no avail.
Exec('cmd.exe', '"/c "C:\Windows\System32\inetsrv\appcmd.exe" list site > "c:\test\temp.txt"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
I can run other commands like add site or add apppool. I can see that the cmd window opens but since opening and closing is almost instantaneous, I can't check the output on the window.
The return value of Exec is True.
I'm not exactly sure what is going wrong as I am not getting any error while executing the code.

Related

Bash script output not showing up during execution? [duplicate]

This question already has answers here:
Can I export a variable to the environment from a Bash script without sourcing it?
(13 answers)
Closed 3 years ago.
I have created a virtual environment on my debian system and i made a script that activates it (should).
However when i execute the script nothing shows up, not even an error, my guess is that it is running in a different shell or something but I don't know how to solve it.
Here is the code of the script
#!/bin/bash
source ~/PythonEnv/environments/my_env/bin/activate
I have changed the permissions already with chmod u+x, so that is not a problem.
When i execute the script nothing shows up at all. Any thoughts???
Add set -x at the beginning of your bash script will do the trick.
-x Print commands and their arguments as they are executed.
You can see more bash options here
http://linuxcommand.org/lc3_man_pages/seth.html
Adding x-permissions is not necessary, since you are using source with an absolute path. Of course this sets the environment only which is executed by the shell script which you have posted here. If you want the changes in your interactive shell, it is pointless to do it inside a script. You have to source the activate script in your shell (respectively inside that process where you want the environment to be modified).

Python script writes no output when stdout is redirected to a file [duplicate]

This question already has answers here:
Disable output buffering
(16 answers)
Using tee to get realtime print statements from python [duplicate]
(1 answer)
Closed 4 years ago.
I got a python script running on startup on my raspberry pi (which works fine) where I want to append the output to an existing text file.
I got this code in my /etc/rc.local file (I tried the same with cron, but there it doesn't even start the script for some reason).
python3 /home/pi/script.py >> /home/pi/log.txt
Unfortunately, no matter what I try, the log file is always empty, except when I run the same command directly AND abort the script by pressing ctrl+c and not ctrl+z. It seems that the script has to shut down in a correct way before it writes anything to the file, but I want it to gradually save the file with every single output.
Edit: I solved it. Apparently it's normal that the file gets only written after a certain amount of memory is filled or the script is finished (Which it never was in my case, as I always restarted the pi before that could happen). Add the flag -u to instantly write to file.
python3 -u /home/pi/script.py >> /home/pi/log.txt
If you are using print to output text, its argument flush might help you:
print('Hello, World', flush=True)
Otherwise:
import sys
sys.stdout.write('Hello, world\n')
sys.stdout.flush()
will have the same effect.

bash can't find ./script1.sh when it is called from another script2.sh [duplicate]

This question already has answers here:
Run a script in the same directory as the current script
(4 answers)
Closed 5 years ago.
I have this issue of "./script1.sh not found" when called from another script2.sh which is actually bounded to a keyboard shortcut (control+e).
When I press control+e the script2.sh instantly opens up a new terminal and starts performing its task, but when it has to make a call to script1.sh, it shows this error i.e: sh: 1: ./script2.sh: not found
it works fine when I run it manually in the terminal which is meant to be the current working directory i.e HOME, but it doesn't work when starts from the shortcuts i.e control+e, it perform half its task.
The problem is that these scripts have set different paths as
"./exampleProgam" or "./exampleScript" and doesn't have a full path like "/home/user/program" or "/home/user/script" .
So i don't want to go throw around 70 files and manually change paths one by one to full paths like "/home/user/folder".
I will also have to write extra code in order to get the home dir path.
All these scripts and C programs are placed in one folder i.e folder1 in the home direcory: /home/user/folder1/script2.sh while script1.sh is placed in the
/home/user/script1.sh
.
and where does the terminal shell opens up by default.?? becuase when i press the control+e and the program starts in the shell , it doesn't shows any path etc but just starts executing.
I would strongly recommend you to go ahead and fix the path actually.
Or maybe you could add your code and ask for help on how to edit/modify those lines (maybe using sed, as mentioned in the comments)/
But since you have not shown your code, and if its really that hard to correct it now, maybe you can try adding cd /home/user/script/ as the first line in your script1.sh file. This will change the current directory for further commands.

Cannot run a shell script created on Windows [duplicate]

This question already has an answer here:
Why is a shell script giving syntax errors when the same code works elsewhere? [duplicate]
(1 answer)
Closed 7 years ago.
I seem to be having a weird problem, the solution for which might be dead simple and I am just being blind.
My development environment is Windows. I create a deployment archive file, within which contains a shell script file (called install.sh). I sftp this archive over to a linux environment, untar it and try to run execute the script (after chmod to make it executable) and I get this error:
syntax error: unexpected end of file
I don't notice any errors in the file. I delete this file, create a new install.sh, copy over the exact contents from my Windows env, chmod it again, run it again and this time it runs fine!
I have no idea why it does not run the first time I untar it. Any help appreciated!
Check your file:
cat --show-nonprinting file
Remove carriage returns from Windows/DOS:
tr -d "\r" < file > fixed_file
Linux and Windows uses different end of line (CL or CLRF), or maybe it's an encoding problem. You should check the differences between the running sh and the non-running one.

Create files in Inno Setup setup needed by the [Files] section

In my Inno Setup script, I need to execute a command that generates temp files that are to be copied in the [Files] section. I have tried the following:
; cd to the directory of the Inno Setup script and execute a python file
#expr Exec('cmd /C "cd /d %cd% & C:\Python34\python.exe run.py"','','',1,SW_HIDE)
This does not seem to execute as I do not see the files created, which can obviously not be included in the installer.
Along the same lines, how would I execute a command when complete to delete these temp files?
Edit I did execute the cmd by hand and validated that it works
It should be:
#expr Exec('cmd.exe', '/C "cd /d %cd% & C:\Python34\python.exe run.py"','',1,SW_HIDE)
The cmd.exe is the process you are executing, the rest are arguments.
Though even better would be to do without cmd.exe as you do not need it actually:
#expr Exec('C:\Python34\python.exe', 'run.py','c:\startupfolder',1,SW_HIDE)
See Inno Setup Preprocessor: Exec.
Though personally, I'd create a batch file that first runs the Python and then runs Inno Setup compiler. It's way easier and more understandable.

Resources