Back to Blog

VuGen: Open A File On A Remote Machine

The user wants to open a file existing on a remote machine in VuGen, but using the fopen function causes a C interpreter error. What this error means is that there was something wrong in the syntax, but the problem comes up only when file is stored in the remote machine.

The host name itself contains two backslashes as a part of the name. So, in order to specify the complete path of the host machine, you need to precede each backslash with another backslash.

NOTE: when adding script to Controller, you need to add yourfile.txt to Controller -> Details…-> More -> files

EXAMPLE:
This should be the correct way of writing a open:

int *fp;
fp=(int *) fopen("\\\\machine_name\\shared_name\\dir_name\\filename","attribute");

Alternative solution
Alternatively, you can insert your file in the script directory, then specify full path of the file in the vuser directory on the remote machine using the function lr_get_attrib_string("usr"). For example,

long stream;
char file_path[100];
Action1()
{

    sprintf(file_path,"%s\\yourfile.txt",lr_get_attrib_string("usr"));
    if((stream = fopen(file_path,"r" ))!=NULL)

    {
        lr_output_message(file_path);
        fclose( stream );
    }

    else
    lr_output_message("the file can't be opened");

    return 0;
}

——————————-

Scott

Back to Blog