Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I'm trying to setup a script that executes a file that is downloaded from a URL.
At the moment, I have this code, which will just launch default browser, then access the URL typed into an input box (which then results in the download starting).
$inputBox = GUICtrlRead($downloadsURL)
ShellExecute($inputBox)
The file is currently being downloaded to the current logged in users "Downloads" directory (Windows Box).
What would be a "robust" solution for executing the downloaded file?
The filename changes often... would there be a way to rename the downloaded file?
Or maybe ensure I have a "clean" Downloads directory first, then have autoit automatically execute whatever file is in the directory after running the script?
You should always clean up your original download files. Leaving wasted space isn't fare to the end user.
You haven't really given us much to go on. GUICtrlRead simply means you're reading a control (I assume an Input box). And if that's the URL, then I would suggest using InetGet() to download the file to a specific place, then use Run or ShellExecute to run the file (if that's the kind of file that needs to be run that way).
So it might look this way:
Global $gszDir = #DocumentsCommonDir
Global $gszFileName = "mydownloadfile.exe"
Global $gszURL = "URL To File To Download"
_DownloadAndRemoveOriginal($gszURL, $gszDir, $gszFileName)
If #error Then
MsgBox(16 + 262144, "Error", "Error downloading: " & #error)
Exit 1
EndIf
Func _DownloadAndRemoveOriginal($szURL, $szDirectory, $szFileName)
; remove old downloaded file
Local $szFullPath = $szDirectory & "\" & $szFileName
If FileExists($szFullPath) Then
FileDelete($szFullPath)
EndIf
; download and wait for download to complete
Local $iGet = InetGet($szURL, $szFullPath, 1, 0)
If Not $iGet Then
; failed
Return SetError(1, 0, 0)
EndIf
Local $iRet = ShellExecute($szFullPath)
Return SetError(0, 0, $iRet)
EndFunc
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 12 months ago.
Improve this question
I am using vi editor for UNIX. Sometimes I am experiencing an issue with getting out of vi editor, where I go to press esc then type ":wq" or "q!" to quit, but it is not escaping. vi editor just enters weird symbols/characters and I can't get out. What do I do to escape and exit when esc won't escape?
There are few more commands for that apart from the one you are using
Shift+zz to save (if modified )and exit
:cq quit without writing
EDIT :
I found some more commands that I just learned .
There are many ways to exit from vi editors, and you can use some of these commands to exit from other editors
Press F2, this will drop you in Insert Mode, now press: q and hit enter
another way is to press Ctrl + c or ctrl + z command to exit the vi editor forcefully.
press ZZ (shift+z+z). it will save and exit.
Ctrl + [ will also work like escape key.
the 3rd , and 6th command may or may not work on every system, as it depends on terminal's setting and system itself.
or you can do map certain keys to behave like escape, please refer this post , that will save you some keystrokes.
For me this worked:
CTL + c (this is equal to ESC in your case)
:wq! (to write save and quit) and then click enter
have you tried ESC then "ZZ"?
seems to work as a last result for me.
This can happen when vi is started with TERM=linux. You can use the set term command to solve this problem.
Set the TERM to vt100 with one of the following commands depending on the shell.
csh or tcsh: setenv TERM vt100
sh: TERM=vt100; export TERM
ksh, bash, or zsh: export TERM=vt100
vi should work without setting the terminal in kx mode(refer to this for a similar issue: https://unix.stackexchange.com/questions/86742/term-linuxxterm-vi-in-an-xterm-or-the-aaabbbbbbccddd-problem).
In order to save this, add the set TERM command to ~/.vimrc file so the option is loaded when starting vi.
Have you tried ^z followed by "kill" the process?
I just had this issue with editor of command line of Git Bash and what worked was press Esc and then :q!. When I typed only q!, it did not work.
press the following shift + esc
look at bottom left corner
write the following colon included :wq
while Fileupdate <= Filecount:
print(Fileupdate)
url = 'http://www.whatever.com/photo/'+str(Fileupdate)+'.jpg'
try:
a = urllib.request.urlopen(url)
except urllib.error.HTTPError as err:
if err.code == 404:
Fileupdate = Fileupdate + 1
continue
urllib.request.urlretrieve(url, str(Fileupdate)+'.jpg')
Fileupdate = Fileupdate + 1
continue
It will search through the website and identify the web address to download the file from but starts the download and then freezes everytime after downloading 262.1kb of the file. It won't download the rest of the file and it won't continue searching through the rest of the series. Wish I hadn't lost my old code anymore...like a dummy I just started saving over top the old code. At least it worked with a few flaws that I could probably now correct. This isn't working worth a crap.
I have a document that is used by multiple people, and we have to continually check if the file is in use and by who.
I was wondering if there is anyway in R that I could obtain the status of an .xlsx file, if it is closed or open, and who has the file open.
I would then push this result to a HTML page which would refresh on a regular basis, this should then remove the need for the manual checking.
Here is a starting point you might consider. This option is using C code you can compile in with R Cmd and call from R.
In a file "islocked.c" paste this:
#include <stdio.h>
#include <share.h>
void testLock(int *locked, char **filename)
{
FILE *stream;
if( (stream = _fsopen( *filename, "wt", _SH_DENYWR )) != NULL ) {
fclose( stream );
*locked = 0;
} else {
*locked = 1;
}
}
Open a command prompt (windows | find | 'cmd')
Change into the folder you saved the file above
From your command prompt c:\ type the following
"Program File\R\R-3.1.2\bin\r" CMD SHLIB islocked.c
It shouldn't throw any errors or warnings and create a .o and .dll file as a result.
Now in R:
dyn.load('c:\pathtothe_c_file\islocked.dll')
result->.C('testLock', islocked=as.integer(0), filename="d:\tools\r\test.dll")
result$islocked
[1] 1
The dll is locked by R so this should return 1. Try the .o file and it should return 0. There is an API in Windows 7 and newer called IFileInUse which may return the process and possibly the user that has the file open that you might review if you need more information.
IsFileInUse API:
http://msdn.microsoft.com/en-us/library/windows/desktop/ee330722%28v=vs.85%29.aspx
A utility from Microsoft that runs on a command line you can shell to from R that may produce what you need, if you are able to install tools on the server:
http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
I'm newbie to nacl. And I find out there are so many 0 byte files in the directory (nacl_sdk/pepper_38/toolchain/win_*/bin).
When I change the project platform to NaCl64 and compile(hello_nacl_cpp), there comes out an error
(error MSB6006: “D:\nacl_sdk\pepper_38\toolchain\win_x86_newlib\bin\x86_64-nacl-gcc.exe”已退出,代码为 -1)
But I can debug the example "hello_world_gles" with PPAPI platform, so I'm not sure the environment is ok.
Anyone can tell me something? Thanks!
Answer my question.
As #binji says we should use cygtar.py(which is in the dirctory sdk_tools) to extract the file.
Here we go:
Open cygtar.py with your text editor, you will find a class named CygTar who is the real worker.
Move dwon, and insert a snippet of code below Main function.
def MyLogic():
os.chdir('D:\\nacl_sdk\\sdk')
# tar = CygTar('naclports.tar.bz2', 'r', True) #here must use linux file path
tar = CygTar('naclsdk_win.tar.bz2', 'r', True)
tar.Extract()
Then replace sys.exit(Main(sys.argv)) with sys.exit(MyLogic()) at last of file.That all.
Note: If you have learned python, you will know code indent is very important in python, be careful.
And the final code should looks like this:
This is really a newbie question - but basically, how do I enable a template for certain filetypes.
Basically, I just want the template to insert a header of sorts, that is with some functions that I find useful, and libraries loaded etc.
I interpret
:help template
the way that I should place this in my vimrc
au BufNewFile,BufRead ~/.vim/skeleton.R
Running a R script then shows that something could happen, but apparently does not:
--- Auto-Commands ---
This may be because a template consists of commands (and there are no such in skeleton.R) - and in this case I just want it to insert a text header (which skelton.R consist of).
Sorry if this question is mind boggeling stupid ;-/
The command that you've suggested is not going to work: what this will do is run no Vim command whenever you open ~/.vim/skeleton.R
A crude way of achieving what you want would be to use:
:au BufNewFile *.R r ~/.vim/skeleton.R
This will read (:r) your file whenever a new *.R file is created. You want to avoid having BufRead in the autocmd, or it will read the skeleton file into your working file every time you open the file!
There are many plugins that add a lot more control to this process. Being the author and therefore completely biased, I'd recommend this one, but there are plenty of others listed here.
Shameless plug:
They all work in a relatively similar way, but to explain my script:
You install the plugin as described on the linked page and then create some templates in ~/.vim/templates. These templates should have the same extension as the 'target' file, so if it's a template for .R files, call it something like skeleton.R. In your .vimrc, add something like this:
let g:file_template_default = {}
let g:file_template_default['R'] = 'skeleton'
Then create your new .R file (with a filename, so save it if it's new) and enter:
:LoadFileTemplate
You can also skip the .vimrc editing and just do:
:LoadFileTemplate skeleton
See the website for more details.
Assume that your skeletons are in your ~/.vim/templates/ directory, you can put this
snippet in your vimrc file.
augroup templates
au!
" read in templates files
autocmd BufNewFile *.* silent! execute '0r ~/.vim/templates/skeleton.'.expand("<afile>:e")
augroup END
Some explanation,
BufNewFile . = each time we edit a new file
silent! execute = execute silently, no error messages if failed
0r = read file and insert content at top (0) in the new file
expand(":e") = get extension of current filename
see also http://vim.wikia.com/wiki/Use_eval_to_create_dynamic_templates
*fixed missing dot in file path
Create a templates subdirectory in your ~/.vim folder
$ mkdir -p ~/.vim/templates
Create a new file in subdirectory called R.skeleton and put in the header and/or other stuff you want to automagically load upon creating a new ".R " file.
$ vim ~/.vim/templates/R.skeleton
Then, add the following to your ~/.vimrc file, which may have been suggested in a way by "guest"
autocmd BufNewFile * silent! 0r $HOME/.vim/templates/%:e.skeleton
Have a look at my github repository for some more details and other options.
It's just a trick I used to use .
It's cheap but If you ain't know nothing about vim and it's commands it's easy to handle.
make a directory like this :
~/.vim/templates/barney.cpp
and as you konw barney.cpp should be your template code .
then add a function like ForUncleBarney() to end of your .vimrc file located in ~/.vimrc
it should be like
function ForBarneyStinson()
:read ~/.vim/templates/barney.cpp
endfunction
then just use this command in vim
:call ForBarneyStinson()
then you see your template
as an example I already have two templates for .cpp files
:call ForBarney()
:call ACM()
sorry said too much,
Coding's awesome ! :)
Also take a look at https://github.com/aperezdc/vim-template.git.
I use it and have contributed some patches to it and would argue its relatively full featured.
What about using the snipmate plugin? See here
There exist many template-file expanders -- you'll also find there explanations on how to implement a rudimentary template-file expander.
For my part, I'm maintaining the fork of muTemplate. For a simple start, just drop a {ft}.template file into {rtp}/template/. If you want to use any (viml) variable or expression, just do. You can even put vim code (and now even functions) into the template-file if you wish. Several smart decisions are already implemented for C++ and vim files.