I'm trying to do a "tip" command (suggest in Italian).
Previously the command was called pool but I decided to rename it, but now it finds me both commands and neither of them work. And when it MAGICALLY works it gives me the error in the title.
I don't even know what code to leave for this problem, you tell me if you need something
Related
Trying to debug a program in Scilab, I inserted a couple
of "print" instructions to track what is going on.
At first, I used the %io(2) output "file" which, according
to the Help, stands for the console. Nothing happened.
Then I used an actual filename:
print("C:\Leszek\Xprmnt\scl\Ovsjanko\K3ScilabLog.txt", "START! \n \n \n \n GOING \n")
which does print to that file, but when the dust has settled
and I want to inspect the file what I find inside is just the last
message (just before the program crashed), even though there should
have been others before it, including the "START" etc in the quote above.
Apparently, every print command reopens the file for writing as a clean slate,
overwriting whatever was in it before. Looking into Help and online docs
I didn't find any options or parameters that I could use to change this.
What I want is, obviously, the output from all my print commands since the
beginning of the program, either on the console or in a text file.
TIA.
Just use disp("some text") or mprintf("format",var1,...,varn), both will display on the console. If you need to write in a file use fd = mopen("file.txt") then mfprint(fd,"format",var1,...,varn).
I have a problem with a project in Visual Studio. The project is created as an empty project, and then a .c file was added. The problem is that the console closes immediately after the program ends when I redirect input to a file.
I tried going to Properties > Linker > System and selecting /SUBSYSTEM:CONSOLE option, but it doesn't solve this. This always worked for me, but now when I redirected the input, the console closes right after the program execution and I can't see the output.
I redirected the output by adding <"in.txt" in Configuration properties > Debugger > Command, and it works exactly the way I wanted, except the console closes too soon. This problem doesn't occur when I redirect the output.
Also using getchar(), scanf(...) or system("pause") didn't work.
I would love to solve this by only changing some project settings and without adding some extra code to a program if possible, but any solution is appreciated.
Edit: As I stated above, I have tried several things, including some answers from similar questions, but none of them helped.
It's standard windows behavior that a console program automatically gets a new console window when not started from an existing one and this new window is automatically closed as soon as the program ends. So the key to force the window to stay open from withing your program is to prevent program termination.
With things like getchar(), you rely on the fact that these calls block until more input is available. This works fine as long as input actually comes from the console. But when you redirect input to come from a file, there will always be input available -- either there's more to read from the file or you'll instantly get an error (e.g. for EOF). That's the reason all these "tricks" don't work any more.
A simple and very unclean version is to just add an empty loop to the end of your program, so it never exits. On the windows platform, this could be something like
for (;;) Sleep(1000);
The call to Sleep() (include windows.h to use it) makes sure this loop doesn't burn CPU cycles. You'll have to forcefully end your program by hitting Ctrl+C or closing the window. Of course, don't leave this loop in your final program, it would be quite annoying when started from an existing console window.
There might be better solutions to this problem, but I hope I could explain you why this is happening.
Because of my slightly obsessive personality, I've been losing most of my productive time to a single little problem.
I recently switched from Mac OS X Tiger to Yosemite (yes, it's a fairly large leap). I didn't think AppleScript had changed that much, but I encountered a problem I don't remember having in the old days. I had the following code, but with a valid filepath:
set my_filepath to (* replace with string of POSIX filepath, because typing
colons was too much work *)
set my_file to open for access POSIX file my_filepath with write permission
The rest of the code had an error which I resolved fairly easily, but because the error stopped the script before the close access command, and of course AppleScript left the file reference open. So when I tried to run the script again, I was informed of a syntax error: the file is already open. This was to be expected.
I ran into a problem trying to close the reference: no matter what I did, I received an error message stating that the file wasn't open. I tried close access POSIX file (* filepath string again *), close access file (* whatever that AppleScript filepath format is called *), et cetera. Eventually I solved the problem by restarting my computer, but that's not exactly an elegant solution. If no other solution presents itself, then so be it; however, for intellectual and practical reasons, I am not satisfied with rebooting to close access. Does anyone have insights regarding this issue?
I suspect I've overlooked something glaringly obvious.
Edit: Wait, no, my switch wasn't directly from Tiger; I had an intermediate stage in Snow Leopard, but I didn't do much scripting then. I have no idea if this is relevant.
Agreed that restarting is probably the easiest solution. One other idea though is the unix utility "lsof" to get a list of all open files. It returns a rather large list so you can combine that with "grep" to filter it for you. So next time try this from the Terminal and see if you get a result...
lsof +fg | grep -i 'filename'
If you get a result you will get a process id (PID) and you could potentially kill/quit the process which is holding the file open, and thus close the file. I never tried it for this situation but it might work.
Have you ever had the Trash refuse to empty because it says a file is open? That's when I use this approach and it works most of the time. I actually made an application called What's Keeping Me (found here) to help people with this one problem and it uses this code as the basis for the app. Maybe it will work in this situation too.
Good luck.
When I've had this problem, it's generally sufficient to quit the Script editor and reopen it; a full restart of the machine is likely excessive. If you're running this from the Script Menu rather than Script Editor, you might try turning off the Script Menu (from Script Editor) and turning it back on again. The point is that files are held by processes, and if you quit the process it should release any lingering files pointers.
I've gotten into the habit, when I use open for access, of using try blocks to catch file errors. e.g.:
set filepath to "/some/posix/path"
try
set fp to open for access filepath
on error errstr number errnom
try
close access filepath
set fp to open for access filepath
on error errstr number errnom
display dialog errnum & ": " & errstr
end try
end try
This will try to open the file, try to close it and reopen it if it encounters and error, and report the error if it runs into more problems.
An alternative (and what I usually do) is that you can also comment out the open for access line and just add in a close access my_file to fix it.
I am wanting to make a terminal app that stores information about files/directories. I want a way to keep the information if the file is moved or renamed.
What I thought I could do is have a function execute before any command is run. I found this:
http://www.twistedmatrix.com/users/glyph/preexec.bash.txt
But I was wondering if this would be a good way to go about it. Or should I do something else?
I would like to call that function from a C program whenever mv is entered I suppose.
If what you're trying to do is attach some sort of metadata to files, there's a much better supported way to do that -- extended attributes.
Another solution might be to use the file's inode number as an index into a database you maintain yourself.
Can you alias the mv command? in .profile or .bashrc
alias mv=/usr/bin/local/mymv
where mymv is a compiled executable that runs your C code function and calls /usr/bin/mv.
precmd and preeexec add some overhead to every bash script that gets run, even if the script never calls mv. The downside to alias is that it requires new code in /usr/local and if scripts or users employ /usr/bin/mv instead of mv it will not do what you want. Generally doing something like this often means there is a better way to handle the problem with some kind of service (daemon) or driver. Plus, what happens if your C code cannot correctly handle interesting input like
mv somefille /dev/null
If you want to run command each time after some command was executed in the terminal, just put the following in ~/.bashrc:
PROMPT_COMMAND="your_command;$PROMPT_COMMAND"
If you want your command to be executed each time before mv is executing, put the following in ~/.bashrc:
alias mv="your_script"
Make sure that your script will execute real mv if needed.
You can use inotify library to track filesystem changes. It's good solution, but once user remove file, it's already gone.
You might be able to make use of the DEBUG trap in Bash.
From man bash:
If a sigspec is DEBUG, the command arg is executed before every
simple command, for command, case command, select command, every
arithmetic for command, and before the first command executes in
a shell function
I found this article when I was forced to work in tcsh and wanted to ensure a specific environemtn variable was present when the user ran a program from a certain folder (without setting that variable globally)
tcsh can do this.
tcsh has special alias, one of which is precmd
This can be used to run a script just before the shell prompt is printed.
e.g. I used set precmd 'bash $HOME/.local/bin/on_cd.sh'
This might be one of the very few useful features in csh.
It is a shame but I don't think the same or similar feature is in bash or other sh derivites (ash, dash etc). Related answer.
Hello I'm trying to get Perforce syntax to obtain (for example using "fstat") list of files only in given folder (depot), without rubbish from all sub-folders. But I was not able to find anything in the docs, nothing related when using Google, even experimenting with ".", ".../." etc. lead me to nowhere...
Is that because it's not possible at all? I can't understand why... Isn't that a performance back hit?!
Thanks in advance.
Seb.
A single '*' expands to "all files in this directory" in p4 (no subdirectories). So, e.g. at a Unix shell prompt, in the correct directory in a perforce client:
$ p4 fstat '*'
You need to quote or escape the * to avoid the shell expanding it, of course;-).
Ah finally.
It was partially my own fault - I'd set ExceptionLevel to ExceptionOnBothErrorsAndWarnings... I needed full debug... Unfortunately:
When exception was raised - there was no Response object created, and I could not read the warning message, which wasn't part of the exception message (or object).
Using '//depot/Folder1/Folderx/*' thrown warning "No such file(s)!" - what is not something that developer might expect... As not being any special case...
It seems that I have still much to learn on the Perforce though :-/
Thank you guys for your posting.
Seb.