Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:23:44+00:00 2026-06-14T08:23:44+00:00

I need to execute command line commands and tools that accept ut8 as input

  • 0

I need to execute command line commands and tools that accept ut8 as input or generate an ut8 output.
So i use cmd an it works, but when i try this from php with exec it doesn’t work.
To make it simple i tried simple output redirection.

When i write direct in command prompt:

chcp 65001 > nul && echo цчшщюя-öüäß>utf8.txt

The uft8.txt is created an the content is correct.

цчшщюя-öüäß

When i use the exec function from php:

$cmd = "chcp 65001 > nul && echo цчшщюя-öüäß>utf8.txt";
exec($cmd,$output,$return);
var_dump($cmd,$output,$return);

the content in the utf8.txt is messed up:

¥Å¥Î¥^¥%¥Z¥?-ÇôǬÇÏÇY

I am using Win7,64bit with (Console) Codepage 850.

What should i do to fix that?

Additional Infos:
I am trying to overcome some issues with reading and writing of utf8 filenames on windows.
PHP file functions fail: glob, scandir, file_exists can’t handle utf8 filenames correctly. File are invisible, skipped, names are changed …
Therefore i want to avoid php file functions and i am looking for some php extern filehandling.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:23:46+00:00Added an answer on June 14, 2026 at 8:23 am

    Since i couldn’t find an easy, fast and reliable internal php solution, i am ending with using that i know it’s work. Cmd-Batch-File.
    I make a small function that generate a cmd batch file in runtime.
    Its just prepends the the chcp (change the codepage) command in order to switch to unicode.
    And parse the output.

    function uft8_exec($cmd,&$output=null,&$return=null)
    {
        //get current work directory
        $cd = getcwd();
    
        // on multilines commands the line should be ended with "\r\n"
        // otherwise if unicode text is there, parsing errors may occur
        $cmd = "@echo off
        @chcp 65001 > nul
        @cd \"$cd\"
        ".$cmd;
    
    
        //create a temporary cmd-batch-file
        //need to be extended with unique generic tempnames
        $tempfile = 'php_exec.bat';
        file_put_contents($tempfile,$cmd);
    
        //execute the batch
        exec("start /b ".$tempfile,$output,$return);
    
        // get rid of the last two lin of the output: an empty and a prompt
        array_pop($output);
        array_pop($output);
    
        //if only one line output, return only the extracted value
        if(count($output) == 1)
        {
            $output = $output[0];
        }
    
        //delete the batch-tempfile
        unlink($tempfile);
    
        return $output;
    
    }
    

    Usage: just like php exec():

    utf8_exec(‘echo цчшщюя-öüäß>utf8.txt’);

    OR

    uft8_exec(‘echo цчшщюя-öüäß’,$output,$return);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to execute a SELECT ... from Sybase's command line tool, FSQL ,
I have a script that generate me some command that I must execute... Example:
I need to execute ssh from windows command line by providing password in a
I have a set of command line tools that I'd like to run in
I have a long text file of redis commands that I need to execute
I need to execute a command 100-200 times, and so far my research indicates
I need to execute some commands in batch mode (e.g., via Rscript). They work
I need to execute the given commands as root and sudo user using Java.
hi I need to read the command line standard out after executing a haskell
I use the Exiv2 command line tool on Linux to edit image metadata like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.