I'm using PyCharm community edition to create a love2d application. I've created a hotkey that runs a .bat file to run it with lovec.exe which is opens the console as the app runs, then i've created an external tool to run the .batfile through a keyboard shortcut, when i use it, the console opens within PyCharm, which doesn't write anything, and after closing the app, everything that was meant to have been written appears, when i run the .bat file outside of PyCharm it functions perfectly.
I would like to know if there's either an obvious fix to that or, just how to run the console outside of pycharm through an external tool.
This issue is due to the way Lua delays writing files, known as "buffering." To change it, put the following command at the top of your file:
io.stdout:setvbuf( 'no' ) -- Switches buffering for stdout to be off
Read more in Lua's manual:
file:setvbuf (mode [, size])
Sets the buffering mode for an output file. There are three available modes:
"no": no buffering; the result of any output operation appears immediately.
"full": full buffering; output operation is performed only when the buffer is full or when you explicitly flush the file (see io.flush).
"line": line buffering; output is buffered until a newline is output or there is any input from some special files (such as a terminal device).
For the last two cases, size specifies the size of the buffer, in bytes. The default is an appropriate size.
Related
I want to run a .blf file using the Replay Block in CANalyzer . I want to run this file in a constant loop for emulation purpose. Is it possible using CAPL or can some one instruct me how to do this even without CAPL.
You don't need CAPL to replay a log file in a loop.
Right click the Replay block
In the "General" tab, enable "Repetitive output sending mode"
How can you instruct an application or the printer to only print the first page, a page range or just odd or even pages of a file? I attempt this with the help of the Preview app, which looks promising:
set theFile to "[file-path/file]""
tell application "Preview"
activate
print theFile with properties {target printer:"Printer", ending page:1} without «class pdlg»
--these properties isn't available for the printer app, here just limiting amount of printed pages
quit
end tell
But with this I'm bitten by the sandboxd process that tells me the file can't be opened for printing and I get a deny file-read-data result in the log.
In the CUPS suggestion by adamh I encounter issues with umlauts and have other execution issues as well, possibly also because of sandbox rules. The code works from the command line, but not when called in automated fashion.
I tried to look up useful examples of the print command in a reference, in my books and tried searching the online Apple references, but I can't seem to find many examples fitting to the present day situation with sandbox, if any.
You could script printing by command line tool lp & lpr.
These talk to CUPS, Common Unix Printing System
To target pages / ranges:
lp -o page-ranges=2-4 "my_great_document.pdf"
To call it from applescript use do shell script
e.g,
do shell script "lp -o page-ranges=2-4 'my_great_document.pdf'"
For more ideas see: http://www.cups.org/documentation.php/options.html
I'm very new to IDL (trying to do a POC for someone using it) and I am trying to run an external command. The line of code I have added is this:
spawn, 'C:\Program Files\ITT\IDL\IDL80\products\envi48\save_add\visual.exe'
I thought this was all that was needed to launch an external command. When I run the app, i can use the debugger to step through the code, and when I get to this line and Step over, my executable does not run. I see no messages in the debugger indicating any type of error.
I put the file visual.exe in the directory and can run it by hand with no issues. It just seems to step right over the code without executing it or reporting any error.
You can use the form:
spawn, cmd, result, errResult
to get the any error messages that might be generated from the cmd. In your particular case, I think you need to quote the path to the executable because of the space in the path.
Your usage of the spawn command is correct. Perhaps visual.exe is exiting prematurely
for some reason (for example, maybe the working directory when run via spawn isn't what
your external program is expecting.)
You might try writing a little script that starts visual.exe, then does a pause,
and then spawn the wrapper script instead of visual.exe directly. That might
give you a chance to see any error messages before the DOS window disappears.
I've got a console application that crashes with an I/O error 6 when the output is redirected to a file. It probably has something to do with the fact that the console application changes the text color, which doesn't make much sense in a file.
This works: c:\dir\app.exe
This crashes: c:\dir\app.exe >out.txt
When I supply >out.txt as a parameter in the IDE (run\parameters\parameters\), I just get >out.txt as a parameter.
How can I debug the application with the stdout redirected to a file instead of the console?
Redirection is made by the command line interpreter, in windows it is cmd.exe
To debug the application, just launch a cmd.exe with propers arguments to launch your application and redirect the output, for example:
cmd.exe /c "yourapplication.exe >redirect.txt"
To make this happen from inside IDE in order to debug, configure cmd.exe as the host application (Run/Parameters):
Put a breakpoint where you want to stop, and launch a new cmd.exe (Project/Load process) with "Run to first source" after load action:
And you're done... the debugger must stop the application at your breakpoint.
You could try remote debugging:
at the beginning of the application, add a ReadLn; which gives you time to attach to the process from within Delphi
start the application from a command line (specifying the >out.txt parameter)
in Delphi, connect with the app process (Run | Attach to Process...), set a breakpoint and then switch to the application to enter a key
Hint: a debugger breakpoint can also be set in code:
asm
int 3
end;
Make sure it isn't failing due to directory permissions. Fully-qualify the output file path to somewhere that you're guaranteed to be able to write. Otherwise, Windows7 may be playing games with the directory. (VirtualStore stuff).
This question already has answers here:
Can one executable be both a console and GUI application?
(9 answers)
Closed 6 years ago.
Is it possible to (and if so, how do I) make a single program work both as a console application and a GUI version using Delphi 2007?
What I am after is that if the program is run with the appropriate command-line options, it should function as a console program, printing output to the console using WRITELN, but if no command line arguments are given it should run as a normal Delphi GUI application?
The catch is that when running as a console application, the command line interpreter waits for the application to terminate before allowing you to enter a new command, whereas a GUI application started from the command line immediately returns you to the command line and the GUI application is started in a detached process. I want this behaviour retained.
I don't mind something like this:
IF GUI THEN StartApplicationAsGUI(ParamStr(0))
ie. I don't mind that I'll have to restart the application using some form of EXECUTE call to start it in GUI mode if needed, as long as the command line interface returns to the command line input when the GUI version is started.
I'd prefer a solution/suggestion that is along the lines of:
<Parse Comnand Line>
IF ConsoleMode THEN
RunConsole(Parameters)
ELSE BEGIN
Application.Initialize;
Application.CreateForm(...)
Application.Run;
END
(or vice-versa, ie. doing things a special way if GUI mode)
so that I can still use Delphi's IDE and VCL when making the GUI interface...
On Windows this is a little bit tricky. Actually the distinction between a console application and a GUI one is a single flag in the PE header. You can easily write console applications that create windows but that way you always have the console window around (you could hide it, though, but that wouldn't be nice when people run your program from cmd).
You can, however write a GUI application that creates a console if it needs to, using the AllocConsole function:
A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, then it can call AllocConsole to create a new console or AttachConsole to attach to another console.
If the calling process creates a child process, the child inherits the new console.
AllocConsole initializes standard input, standard output, and standard error handles for the new console. The standard input handle is a handle to the console's input buffer, and the standard output and standard error handles are handles to the console's screen buffer. To retrieve these handles, use the GetStdHandle function.
This function is primarily used by graphical user interface (GUI) application to create a console window. GUI applications are initialized without a console. Console applications are initialized with a console, unless they are created as detached processes (by calling the CreateProcess function with the DETACHED_PROCESS flag).
However, when run from cmd this will likely cause another console window to appear instead of re-using the existing one. I don't know whether a good solution exists there.
IMO, the best approach here is to have non-visual classes that actually do the work of the program. Then you can call that from a GUI program, and you can also call it from a separate command line program. Both programs are just wrappers around the functionality of your class(es).
This forces the design to be clean too - your classes necessarily are separated from the GUI layer of your application.
http://blogs.msdn.com/oldnewthing/archive/2009/01/01/9259142.aspx
Windows has different values in executable's header for console and UI application (see more details here). So it seems to be impossible to make the same executable to work in both modes.
As an alternative, you can open a console in you UI app, but it will be new console, not the one you've started app from.
AttachConsole() may be used to get a hold of the parents console.
E.g. if the application is started from a cmdline shell, AllocConsole() can be avoided:
if not AttachConsole(ATTACH_PARENT_PROCESS)
then AllocConsole;
More info here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681952(v=vs.85).aspx