How to dump output of Sysninternals handle.exe to a text file? - scripting

I want to see who locks a file, quickly.
So I created a CMD script that will run Handle, put its output in a file and then open that file in the default text editor.
prompt $
cls
handle > handle.txt
handle.txt
When I run the script a new console wnd is open, I see handle running in it, then it quickly closes. It generates a file called handle.txt, but it is empty.
I tried to run handle.exe as admin, but still doesn't work.
What I do wrong?

Related

FTP command works in Excel VBA but not PowerPoint

In my excel VBA code I'm automating the process of running a script ("PULLSCRIPT", which is also created in the code) that runs ftp, opens my FTP address, enters my user and password, pulls a file using mget, and lastly moves that file to another folder using Name. It works in Excel VBA (I click a macro and it does all these steps, no manual input required), but when I copy and paste it to PowerPoint VBA, the line
Shell ("ftp -s:" & sWorkingDirectory & FTP_BATCH_FILE_NAME)
doesn't run. It doesn't give me an error and, F8 stepping through it, it looks like the shell opens (just like when I step through it in Excel), but it never runs PULLSCRIPT (or if it does then it's not working). When I manually open cmd and run the PULLSCRIPT it works, but the point of automating it was so people wouldn't have to do that.
To debug the command execution, add cmd /k in front of it:
Shell ("cmd /k ftp -s:" & ...)
This way, the console window stays open and you can see, what went wrong.

Is there a way to find output of previous runs in IntelliJ?

Every time I run some program, the output of previous run of some other program seems to be overwritten by the new output. Is there a way to see the output of previously run programs?
There is not. In the Run/Debug configuration, on the log tab, you can turn on the option "Save console output to file". (You can set this under the "Defaults" configuration so that it always there by default. That however only applies to the current project. To set as a default for all future projects as well, from the Welcome screen (i.e. close all projects) go to Configure > Project Defaults > Run Configurations) Unfortunately, that output file is (also) overwritten on each new run. To the best of my knowledge, there is no way to add a timestamp to the file name. You can open a feature request asking they enhance this to retain the last x number of runs or allow a timestamp.
In the meantime, there are two options you can use for a workaround.
Option 1 - Logging Framework
The first option is to use a logging framework. This won't include the start up information or any System.out/err that the console has (unless you use something like sysout-over-slf4j). On the same "Logs" tab in the Run/Debug configuration, you can set to have the log file shown in the console tool window. The nice thing is that IntelliJ IDEA only shows new output for that run. But the output from previous runs is still in the log file (assuming your logger is set up to append and not overwrite on new runs). When specifying the log name, you can use wild characters (to deal with things like a date stamp in the log). It use Ant fileset pattern notation. Click the help button on "Edit Log Files Aliases" dialog for more information. By default, IDEA only shows the latest log, unless you select the "Show all files coverable by pattern" on the "Edit Log Files Aliases".
Option 2 - Use a Script
Another option would be to use the "Save console file output to file" option. Then write an external script or Ant task that moves/renamed that output. (You could make it fancy so it only saves the last x runs, rolling the previous ones names.) Then in the run/debug configuration, use either the "Run External tool" or "Run Ant Target" option in the "Before Launch" section to run your script. (Again, you can set this on the default configurations so it is there automatically.) This way your script will run, renaming the file, before the new output is created and overwrites the old.
In addition to the options mentioned by Javaru, it is possible to tell IntelliJ to save all console outputs til a local file:
Edit Run Configuration -> Logs -> Save console output to file

Add options to program's right-click menu

I have a small program that reads a CSV file and outputs it in a different format.
Sometimes I want a different output format so currently I just have another version of the program compiled with slightly different code (it has no GUI, you just click on the exe and it does its job).
Is there a way I can add an option to the context menu of this program to use the different output option, perhaps by running it with a command-line argument?
I mean when right-clicking on the exe file itself, so before it is actually running.
Anything I can find when searching for answers is about editing the shell, via the registry or some other way, however I only want the option to show for this program, not every file in Windows.
Code for the command line that I would be using:
If Environment.GetCommandLineArgs.Count <> 1 Then
If Environment.GetCommandLineArgs(1) = "/output2" Then
'do stuff
End If
End If

Stop command prompt from getting closed after executing a batch file

I used Shell command from Excel VBA to run a certain .bat file. The CMD appears but exits automatically after all lines were executed. I've added the PAUSE command a the end of the bat. file but it's not working. How to stop command prompt from getting automatically closed?
Try using the /K switch to prevent exiting after running the batch file like this:
cmd /K "path to batch file including file name and extension"
e.g.
cmd /K "C:\FOLDER\BATCH FILE.BAT"
or
cmd /K "C:\FOLDER\BATCH FILE.CMD"
Obviously that won't reveal any faults with your batch code, but it won't exit after running - much the same as running the batch file from the command line.
Definitely add some ECHO output lines to indicate progress as it runs and troubleshoot. Perhaps post the file here for more help.
Try opening the command prompt and running the batch file. It is possible that the the dos shell is encountering an error and closing. If the error comes before the execution reaches Pause command, it will not pause for you to read the error and it immediately closes off.
If that doesn't work out, check if you have any exit commands in any of the branches. Alternatively, place echo statements at different places and check if the execution control reaches these echos. This way you can find out if your script if ending at some other branch.
While perhaps not actually answering the posted question, I stumbled upon this question in a search to a very related-question. I was also trying to stop a command prompt from closing as it was erroring out and closing immediately. For me, it was sufficient for me to view the output as what I really wanted was to be able to see the error in order to debug it.
The solution I found was to pipe the output of the command prompt into a text file, like so:
MyScript.bat >> text.txt
This allowed me to see the error I was getting.

How to reload unreal development kit after script change

i am currently learning unreal scripting. i am creating them on visual studio then compile them in it. I have created a level with the actor i have created.
The problem i have is every time i make changes to the script I am closing the UDK and reopen the level to see the changes.
Is there a way of saying to UDK to reload?
If you make changes to the script, you need to close any instances of UDK.exe, whether game or editor.
Here is a workflow to speed up the whole process by using .bat files to run the game or editor.
Create a text file and rename it to run_game.bat. Inside the file put the following text, adjusting the path to match your project settings:
C:\UDK\Kel\Binaries\Win32\udk.exe Level01
Note that Level01 is the name of your level / map file. This .bat file will run your game within that level.
Next, create another .bat file called run_editor.bat and put this text inside:
C:\UDK\Kel\Binaries\Win32\udk.exe editor Level01
By adding the editor parameter, you're asking to run the editor directly with the desired level.
Copy the two .bat files in C:\Users[Your username] for fast access.
Open the command line by pressing Windows + R, then typing cmd and hitting Enter. Type either run_game or run_editor and hit Enter.
If you have uncompiled code, you'll be asked whether to compile it, so say yes. You will also see any errors or warnings that showed up during compile, which is useful. If everything went well after the compile, press the Up key or type in the name of the .bat you are trying to run, and hit Enter.
Using the above method is also faster because it doesn't require you to compile the scripts in Visual Studio.
Unfortunately, no. Changes to UnrealScript require recompiling the .u file, and the game/editor has to be closed so the file can be deleted and recreated.
I'm not sure from your question if you're saying you're reopening the UDK editor every time you want to see the change, or if you're just reopening the game. If you just want to modify the script, compile, and see the result (without modifying the level), you don't have to reopen the editor. You can just run UDK.exe, press the '~' key to bring up the console, and type open yourlevelname. Or you can create a shortcut that runs UDK.exe yourlevelname to start the game on that level. Of course if you want to spawn in and run around, you'll need to put a PlayerStart in your level.