Exemplo n.º 1
0
/* --------------------------------------------------------------------------------------
Name: OS_ShellOutputToFile

Purpose: Takes a shell command in and writes the output of that command to the specified file

Returns: OS_SUCCESS if success
         OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid
         OS_FS_ERROR if Error
---------------------------------------------------------------------------------------*/
int32 OS_ShellOutputToFile(char* Cmd, int32 OS_fd)
{
    char LocalCmd [OS_MAX_CMD_LEN];
    int32 Result;
    int32 ReturnCode = OS_FS_SUCCESS;
    int32 fdCmd;
    char * shellName;

    /*
    ** Check parameters
    */
    if (Cmd == NULL)
    {
        return(OS_FS_ERR_INVALID_POINTER);
    }

    /* Make sure the file descriptor is legit before using it */
    if (OS_fd < 0 || OS_fd >= OS_MAX_NUM_OPEN_FILES || OS_FDTable[OS_fd].IsValid == FALSE)
    {
        ReturnCode = OS_FS_ERR_INVALID_FD;
    }
    else
    {
        /* Create a file to write the command to (or write over the old one) */
        fdCmd = OS_creat(OS_SHELL_CMD_INPUT_FILE_NAME,OS_READ_WRITE);

        if (fdCmd < OS_FS_SUCCESS)
        {
            Result = OS_FS_ERROR;
        }

        else
        {
            /* copy the command to the file, and then seek back to the beginning of the file */

            strncpy(LocalCmd,Cmd, OS_MAX_CMD_LEN);
            OS_write(fdCmd,Cmd, strlen(LocalCmd));
            OS_lseek(fdCmd,0,OS_SEEK_SET);

            /* Create a shell task the will run the command in the file, push output to OS_fd */
            Result = shellGenericInit("INTERPRETER=Cmd",0,NULL, &shellName, FALSE, FALSE, OS_FDTable[fdCmd].OSfd,	OS_FDTable[OS_fd].OSfd, OS_FDTable[OS_fd].OSfd);

            /* Wait for the command to terminate */
           do{
              taskDelay(sysClkRateGet());
            }while (taskNameToId(shellName) != ERROR);

            /* Close the file descriptor */
            OS_close(fdCmd);

        } /* else */

        if (Result != OK)
        {
             ReturnCode =  OS_FS_ERROR;
        }

    }
    return ReturnCode;
}/* end OS_ShellOutputToFile */
Exemplo n.º 2
0
int VCS_shellGenericInit(const char *arg1, const char *arg2, const char *arg3, char **arg4,
                     int arg5, int arg6, int arg7, int arg8, int arg9)
{
    if (OsFileApi_UseReturnCode(OSFILEAPI_SHELLGENERICINIT_INDEX)) 
    {
	/*printf("Inside VCS_shellGenericInit(), returning table value.\n");*/
        return OsFileApi_ReturnCodeTable[OSFILEAPI_SHELLGENERICINIT_INDEX].Value;
    }

    /*printf("Inside VCS_shellGenericInit(), calling shellGenericInit()!!!\n");*/
    return shellGenericInit(arg1, arg2, arg3, arg4,
                     arg5, arg6, arg7, arg8, arg9);
}