Can't open file on Ubuntu

I am using Ubuntu 14 and trying to create a script file to write files, but I get an error every time I try to open the file. 5004

datetime currtime;
bool     newcandle;

string   terminal_data_path = TerminalInfoString( TERMINAL_DATA_PATH );
string   filename           = terminal_data_path + "\\MQL4\\Files\\" + "data.csv";

int      filehandle;

filehandle = FileOpen( filename, FILE_WRITE | FILE_CSV );

if (  filehandle < 0 ){    
      Print( "Failed to open the file by the absolute path " );
      Print( "Error code ", GetLastError() );
    }
else {
      Print( "file opened with sucess" );
    } 

      

How can I fix this problem on Ubuntu?

UPDATE

I tried to change my file to the following:

string terminal_data_path = TerminalInfoString( TERMINAL_DATA_PATH );
string filename           = terminal_data_path + "\\tester\\files\\data.csv";

      

and only for this

string filename = "\\tester\\files\\data.csv";

      

and for this

string filename = "\\files\\data.csv";

      

But I still get the error, but not this time . 5002

5004

+3


source to share


1 answer


MQL4 Permissions by Design Deny / Deny FileIO

There are three directories (with subdirectories) in which working files can be placed :

/HISTORY/<current broker>

- especially for function FileOpenHistory()

;

/EXPERTS/FILES

- general case;

/TESTER/FILES

- especially for testing (link during Strategy Tester operations).

It is forbidden to work with files from other directories .



Decision

Adapt your MQL4 code to match this fact and respect the pre-Build 762 and post-Build 762 differences ("new" -MQL4-local files).

Update

As stated, your MQL4 code (whether you use its updated state or not) should handle exceptions better. Met some awesome filename artifacts. Some platform specific that does not harm wXP but is unable to run (same code) on a VPS hosted VMWServer2008 or LinuxVM encapsulated Wine / MT4 instance.

Read the MQL4-help documentation carefully and create several posthumous tools for further progress.

5002
 ERR_FILE_WRONG_FILENAME
 Wrong file name               -------> pre-test + "fuse" the corner cases

5003
 ERR_FILE_TOO_LONG_FILENAME
 Too long file name

5004                           <------ a good sign, we are on the safer side here
 ERR_FILE_CANNOT_OPEN
 Cannot open file

//-------------------------------------------------------------
//   MT4_GUI_postMortem
//-------------------------------------------------------------    
void MT4_GUI_postMortem( string aFileNAME = "caller forgot to pass aFileNAME"
                         ){
  // SYNTAX
  //         if ( aFileHANDLE == INVALID_HANDLE ) MT4_GUI_postMortem( filename );
  //
     int aLastErrorNUM = GetLastError();
     Comment( "POST-MORTEM >>> [", aFileNAME, "] Threw error ", aLastErrorNUM );
     Print(   "POST-MORTEM >>> [", aFileNAME, "] Threw error ", aLastErrorNUM );

     return;
    }   

      

+2


source







All Articles