FileOpen() always fails with Error 5002 - Bad Filename - metatrader5

I do correctly get the MetaTrader safe folder to write files to via
string path = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\";
however,
int f = FileOpen(path + filename, FILE_READ | FILE_WRITE | FILE_CSV , '\n');
always fails due to the 5002 error - bad filename
Any ideas what am I missing?

Related

CMD,DevCon and Visual Fox Pro

I made a .bat file using DevCon for restarting a device and when run it works.
When i try to run the same file in VFP form using the run command on click it says that DevCon is not recognized.
! cmd /c "C:\Windows\System32\restart.bat"
! "C:\Windows\System32\restart.bat"
I've tried making Sistem32 as a starting path and starting default and it does not work either way. It seems like CMD gets confused in the process. Thanks in advance for any help.
I would instead try using ShellExecute API. ie:
#Define SW_HIDE 0
#Define SW_NORMAL 1
#Define SW_SHOWMINIMIZED 2
#Define SW_SHOWMAXIMIZED 3
Local lcResult
lcResult = ShellExec('C:\Windows\System32\restart.bat', '', 'C:\Windows\System32', SW_NORMAL)
If !Empty(m.lcResult) && error
Messagebox(m.lcResult)
Endif
Function ShellExec
Lparameters tcExecutable,tcParams,tcWorkingDir,tnShowType,tcOperation
Declare Long ShellExecute In "shell32.dll" ;
long HWnd, String lpszOp, ;
string lpszFile, String lpszParams, ;
string lpszDir, Long nShowCmd
tcOperation = Iif(Empty(m.tcOperation), 'Open', m.tcOperation)
tcExecutable = Iif(Empty(m.tcExecutable), '', m.tcExecutable)
tcParams = Iif(Empty(m.tcParams), '', m.tcParams)
tcWorkingDir = Iif(Empty(m.tcWorkingDir), '', m.tcWorkingDir)
tnShowType = Iif(Type('m.tnShowType') # 'N', SW_SHOWNORMAL, m.tnShowType)
Local lnResult, lcError
lcError = ''
lnResult = ShellExecute(0,m.tcOperation,m.tcExecutable,m.tcParams,m.tcWorkingDir,m.tnShowType)
If !( m.lnResult > 32 ) && Error
lcError = GetShExecErrorMsg(m.lnResult)
Endif
Return m.lcError
Endfunc
Function GetShExecErrorMsg
Lparameters tnErrNum
Local Array aErrors[1]
Local lcMessage, lcErrors,lnErrors,ix
TEXT to m.lcErrors noshow
0,The operating system is out of memory or resources. \n
2,The specified file was not found. \n
3,The specified path was not found. \n
11,The .exe file is invalid (non-Win32® .exe or error in .exe image). \n
5,The operating system denied access to the specified file. \n
27,The file name association is incomplete or invalid. \n
30,The DDE transaction could not be completed because
other DDE transactions were being processed. \n
29,The DDE transaction failed. \n
28,The DDE transaction could not be completed because the request timed out. \n
32,The specified dynamic-link library was not found. \n
31,There is no application associated with the given file name extension.
This error will also be returned if you attempt to print a file that is not printable. \n
8,There was not enough memory to complete the operation. \n
26,A sharing violation occurred. \n
ENDTEXT
Clear
lnErrors = Alines(aErrors,m.lcErrors,.T.,'\n')
For ix=1 To m.lnErrors
If ( Val(Chrtran(Left(aErrors[m.ix],;
At(',',aErrors[m.ix])-1),Chr(13)+Chr(10),'')) = m.tnErrNum )
lcMessage = Substr(aErrors[m.ix],At(',',aErrors[m.ix])+1)
Exit
Endif
Endfor
If Empty(m.lcMessage)
lcMessage = 'An unspecified error occurred.'
Endif
Return m.lcMessage
Endfunc

F#: Breaking out of a loop

I am new to programming and F# is my first language.
I have a list of URLs that, when first accessed, either returned HTTP error 404 or experienced gateway timeout. For these URLs, I would like to try accessing them another 3 times. At the end of these 3 attempts, if a WebException error is still thrown, I will assume that the URL doesn't exist, and I will add it to a text file containing all of the invalid URLs.
Here is my code:
let tryAccessingAgain (url: string) (numAttempts: int) =
async {
for attempt = 1 to numAttempts do
try
let! html = fetchHtmlAsync url
let name = getNameFromPage html
let id = getIdFromUrl url
let newTextFile = File.Create(htmlDirectory + "\\" + id.ToString("00000") + " " + name.TrimEnd([|' '|]) + ".html")
use file = new StreamWriter(newTextFile)
file.Write(html)
file.Close()
with
:? System.Net.WebException -> File.AppendAllText("G:\User\Invalid URLs.txt", url + "\n")
}
I have tested fetchHtmlAsync, getNameFromPage and getIdFromUrl in F# Interactive. All of them work fine.
If I succeed in downloading the HTML contents of a URL without using all 3 attempts, obviously I want to break out of the for-loop immediately. My question is: How may I do so?
use recursion instead of the loop:
let rec tryAccessingAgain (url: string) (numAttempts: int) =
async {
if numAttempts > 0 then
try
let! html = fetchHtmlAsync url
let name = getNameFromPage html
let id = getIdFromUrl url
let newTextFile = File.Create(htmlDirectory + "\\" + id.ToString("00000") + " " + name.TrimEnd([|' '|]) + ".html")
use file = new StreamWriter(newTextFile)
file.Write(html)
file.Close()
with
| :? System.Net.WebException ->
File.AppendAllText("G:\User\Invalid URLs.txt", url + "\n")
return! tryAccessingAgain url (numAttempts-1)
}
please note that I could not test it and there might be some syntax errors - sorry if
as we are at it - you might want to rewrite the logging of the invalid url like this:
let rec tryAccessingAgain (url: string) (numAttempts: int) =
async {
if numAttempts <= 0 then
File.AppendAllText("G:\User\Invalid URLs.txt", url + "\n")
else
try
let! html = fetchHtmlAsync url
let name = getNameFromPage html
let id = getIdFromUrl url
let newTextFile = File.Create(htmlDirectory + "\\" + id.ToString("00000") + " " + name.TrimEnd([|' '|]) + ".html")
use file = new StreamWriter(newTextFile)
file.Write(html)
file.Close()
with
| :? System.Net.WebException ->
return! tryAccessingAgain url (numAttempts-1)
}
this way it will only be logged once the attempts where all made

JMeter asserting a response has been successfully downloaded

I am using JMeter to test some of the functionality on my site. Through using the Save Responses to a file element, I have been able to successfully issue a request to download a pdf through JMeter. However, I am curious if there is an assertion to check that a file has actually downloaded (and if possible, is in the format I specified!). I know I can simply look at the file, but I'm hoping to make this more automated. I have checked "Save Successful Responses Only," but I want to ensure a response has actually been saved.
I think you need to use a Beanshell Assertion for this.
Example code to check file presence, size and content type is below:
File file = new File("/path/to/downloaded/file");
//check file existence
if (!file.exists())
{
Failure = true;
FailureMessage = "File " + file.getName() + " does not exist";
}
//check file size
long expectedSize = SampleResult.getBodySize();
long actualSize = file.length();
if (expectedSize != actualSize)
{
Failure = true;
FailureMessage = "Actual file size differs from expected. Expected: " + expectedSize + " and got: " + actualSize ;
}
//check content type
String expectedType = SampleResult.getContentType();
String actualType = file.toURI().toURL().openConnection().getContentType();
if (!expectedType.equals(actualType))
{
Failure = true;
FailureMessage = "Response types are different. Expected: " + expectedType + " and got: " + actualType;
}
See How to Use JMeter Assertions in 3 Easy Steps guide for more information on JMeter Assertions superpower.

How do i play a sound file whare the file name is from a system string

String ^ fileName = textBox5->Text + "DES.wav";
PlaySound(fileName, NULL, SND_FILENAME | SND_SYNC);
The error is saying:
Error 4 error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'System::String ^' to 'LPCWSTR'
No need to mix managed and unmanaged code, use SoundPlayer class:
String ^ fileName = textBox5->Text + "DES.wav";
SoundPlayer^ player = gcnew SoundPlayer(filename);
player->PlaySync(); // or Play for asynchronous execution
http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx

OSX semaphores: Invalid argument in sem_open

While trying to open a semaphore sem_open fails. errno is 22 (), which perror describes as "Invalid argument". I've checked the format of the name (which I think is correct), as well as the flags (O_CREAT and O_EXCL seem pretty hard to mess up. What am I not seeing?
Platform is OS X 10.7. I would have preferred to use a nameless semaphore, but the OS doesn't support sem_init.
int name_counter = 0;
// In order to create a unique semaphore, we iterate until we find a name that
// does not already exist.
do {
char name[48] = {0};
sprintf(name, "xyz_sem_%d", name_counter++);
job_semaphore = sem_open(name, O_CREAT | O_EXCL, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, 0);
} while(errno == EEXIST);
if(0 != errno)
perror("Error opening xyz semaphore");
assert(0 == errno);
I've tried both
sem_open(name, O_CREAT | O_EXCL);
and
sem_open(name, O_CREAT | O_EXCL, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, 0);
to open the semaphore, but get the same result with each. What am I missing?
EDIT: the version above with only two parameters is wrong- the man page says that when including O_CREAT, you must provide all 4 parameters.
EDIT2: errno is only valid when the function returns an error code. In this case, I should have looked at errno only when sem_open returned SEM_FAILED. I didn't do this, and was examining errno when a perfectly good semaphore had been returned. Problem solved.
Before trying sem_open, try sem_unlink()
name should have a leading slash. Try put a "/" in front of name.
ie. sprintf(name, "/xyz_sem_%d", name_counter++);

Resources