[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Can't convert string from native encoding to 'UTF-8' problems

From: 温德鑫 <jackywdx_at_gmail.com>
Date: Thu, 14 Jul 2011 12:23:48 +0800

Thanks a lot! It works. The program can execute svn commands and no error
comes out.

On Thu, Jul 14, 2011 at 4:55 AM, Stefan Sperling <stsp_at_elego.de> wrote:

> On Wed, Jul 13, 2011 at 11:05:34PM +0800, 温德鑫 wrote:
> > HI,all:
> > I wrote a file like this: test.c
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include<locale.h>
> > int main()
> > {
> > FILE *fpipe;
> > char *command="cd /data/cdc/document/;/usr/bin/svn status 73/2788
> > --config-dir /home/svnroot/.subversion 2>&1";
> > char line[256];
> >
> > if ( !(fpipe = (FILE*)popen(command,"r")) )
> > { // If fpipe is NULL
> > perror("Problems with pipe");
> > exit(1);
> > }
> >
> > while ( fgets( line, sizeof line, fpipe))
> > {
> > //printf("%s", line);
> > puts(line);
> > }
> > pclose(fpipe);
> > }
> >
> > and I compiled it, run on the OpenSUSE
> > gcc -o test test.c
> > ./test
> > This way works fine, There is no errors output, but when I use crontab to
> > run it,
> > * * * * * /root/test >> /var/log/test.log 2>&1
> >
> > The error comes out:
> > tailf -f /var/log/test.log
> >
> >
> > svn: Error converting entry in directory '73/2788' to UTF-8
> >
> > svn: Can't convert string from native encoding to 'UTF-8':
> >
> > svn: ?\228?\189?\160?\229?\165?\189.txt
> >
> >
> > The directory contains a file using chinese character,I have searched
> > online,most articles said using " export LC_ALL='en_US.utf-8' " to solve
> > this problem,I try to add this code to the file
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include<locale.h>
> > int main()
> > {
> > FILE *fpipe;
> > char *command="cd /data/cdc/document/;/usr/bin/svn status 73/2788
> > --config-dir /home/svnroot/.subversion 2>&1";
> > char line[256];
> > char *b = setlocale(LC_ALL, "en_US.utf-8");
> > puts(b);
> > b = setlocale(LC_ALL, NULL);
> > puts(b);
> >
> > if ( !(fpipe = (FILE*)popen(command,"r")) )
> > { // If fpipe is NULL
> > perror("Problems with pipe");
> > exit(1);
> > }
> >
> > while ( fgets( line, sizeof line, fpipe))
> > {
> > //printf("%s", line);
> > puts(line);
> > }
> > pclose(fpipe);
> > }
> >
> > I compile it again, run by the crontab, but it does not work, the error
> > still exists. How can I solve this problem?
>
> Running setlocale() in your program is not the same as exporting
> an environment variable. The call to setlocale() in your own program
> will not affect the locale of the program you are spawning via popen().
>
> Try setting the environment variable in your crontab instead.
> Put this in your crontab:
>
> LC_ALL=en_US.UTF-8
> * * * * * /root/test >> /var/log/test.log 2>&1
>
> I think that should work. Most cron programs support setting environment
> variables like this.
>
Received on 2011-07-14 06:24:39 CEST

This is an archived mail posted to the Subversion Users mailing list.