Theory question: How does Oracle's SQL*Plus read script files into memory?
It likely does one of these two options:
Opens the file, reads the entire contents into memory, closes the file, and executes the contents from memory.
Opens the file, reads and executes statements sequentially, closes the file.
Does anyone know for sure which method it uses?
Im writing a program that will modify a script, run the script, and then modify again. This will be simplest if I can modify the script even if it is currently running (Option 1). If Option 2, I will have to wait for the script to be done before I modify again.
Related
I tried to write a program that open itself, reads itself and looks for a certain address or bytes to substitute with an other value.
My objective is to make a program that understands if it's the first time that it's running or not by modifying some bytes the first time it runs (and I don't really like to create a file outside of my program)
The executable can read itself but when it tryes to self-overwrite it throws an error (file used by an other process... As expected)
Is there a way for the program to overwrite itself? If not maybe I can modify just a part of the program that contains just data?
Is there an other simple solution I am not aware of?
(I'm using both Linux and windows as OS.)
From what I understand, your objective is to find out if the program has been run previously or not. Instead of going with the idea you presented why not create a file, could be any file, check upon running if the file is there or not. If it's there then it has been run before else not.
A workaround can be (because it doesn't overwrite itself, it just creates an other file):
copy all content of the original executable
modify what I need
rename di original executable to a fixed name "old version"
write the modified bytes to "original name" (the modified executable)
launch the new executable just created
either have the original executable self delete or delete it from the modified executable just created
I think this gets the job done even if not on the cleanest way (the program has to start from beginning but i guess this is unavoidable)...
If someone still know a better way you are more the welcome to write your idea.
I have some quite long script that I want users to slightly adapt to their scenario before they can copy paste in in some IRB or pry shell.
Most people would, unless paying attention, blindly copy-paste the script in some console. I'd like to stop parsing/executing the rest of the code and (for example) require a user to explicitely validate that he wants to continue running the script (for example via a simple gets that force the user to type enter)
I was thinking of something like (imagine this is the code of a wiki that one would copy paste)
# Start script
[...] # Some stuff
# Copy paste the autorization code you receive from the internet in the `token` variable
string = ("Do not blindly copy-paste, Did you do what was written in the command just above ? We need the token in the `token` variable. If you did it, just press enter. Otherwise abort with CTRL+C and restart the script".purple)
puts string
gets
Service.call(token)
The problem is that the gets/coloration seems to break further execution of the copy pasted script.
My question is, assuming you have a chunk of code that you copy paste using REPL, is there a way to abort/pause the automatic Read-Evaluate print loop via some code contained in the chunk that is copied ?
Basically I'm writing some test procedure that testers can just copy paste in their terminal to check a feature is working. 99% of the time, is is enough to just set some variables and copy-paste the code provided in the examples. But sometimes, there are some (optional) manual steps to be done in the middle of the execution of the code that is copy pasted (like copying a token, retrieving the automatically generated ID, etc.)
I've got two batch files which are running at the same time. Now I need to execute a command in the first batch file, but it will be executed in the second one.
For example, I want to change the color of the second batch program using the first one. If I type in the command color 0a, I want it to be executed in the second batch program.
The batch pseudo code would be like this
execute "goto :a" in "example.bat"
Is this possible?
By the way, I cannot hardcode this stuff and I'm not advanced so if you can please briefly explain what I have to do.
Suppose I have two processes which may write the same content into the same file:
echo "large content" > aFileName
cat aFileName
Does it need synchronization/locks? Could I be sure that after such command the file will have the content not mutilated by race conditions in all processes?
Each process will be using its own file pointer so it should be safe in the normal case.
The only problem I can see is:
process A truncates the file
process A writes some data
process B truncates the file
process B writes less than what process A has written in step #2
process B terminates abnormally without writing the whole file
Now some of the data written in step #2 is lost, even if process A then continues to write the rest.
You could write into a temporary file that's atomically renamed after all the content has been written. Make sure the temporary file is on the same file system as the output, and use some unique identifier (such as the process id) in its name. Also, set up a trap handler to delete the file.
Downside to this solution is that it takes up more storage because multiple copies of the temporary file may be written concurrently, and also some of said temporary files may stay behind as garbage if the process dies without the trap handler being able to run.
I have a program that runs in the command line (i.e. $ run program starts up a prompt) that runs mathematical calculations. It has it's own prompt that takes in text input and responds back through standard-out/error (or creates a separate x-window if needed, but this can be disabled). Sometimes I would like to send it small input, and other times I send in a large text file filled with a series of input on each line. This program takes a lot of resources and also has a large startup time, so it would be best to only have one instance of it running at a time. I could keep open the program-prompt and supply the input this way, or I can send the process with an exit command (to leave prompt) which just prints the output. The problem with sending the request with an exit command is that the program must startup each time (slow ...). Furthermore, the output of this program is sometimes cryptic and it would be helpful to filter the output in some way (eg. simplify output, apply ANSI colors, etc).
This all makes me want to put some 2-way IO filter (or is that "pipe"? or "wrapper"?) around the program so that the program can run in the background as single process. I would then communicate with it without having to restart. I would also like to have this all while filtering the output to be more user friendly. I have been looking all over for ideas and I am stumped at how to accomplish this in some simple shell accessible manor.
Some things I have tried were redirecting stdin and stdout to files, but the program hangs (doesn't quit) and only reads the file once making me unable to continue communication. I think this was because the prompt is waiting for some user input after the EOF. I thought that this could be setup as a local server, but I am uncertain how to begin accomplishing that.
I would love to find some simple way to accomplish this. Additionally, if you can think of a way to perform this, do you think there is a way to also allow for attaching or detaching to the prompt by request? Any help and ideas would be greatly appreciated.
You could create two named pipes (man mkfifo) and redirect input and output:
myprog < fifoin > fifoout
Then you could open new terminal windows and do this in one:
cat > fifoin
And this in the other:
cat < fifoout
(Or use tee to save the input/output as well.)
To dump a large input file into the program, use:
cat myfile > fifoin