朱莉娅-如何使用Cmd类型打开文件?

时间:2019-04-06 16:27:31

标签: file cmd julia

我正在尝试在Julia中物理打开文件(不是读取数据,而是在Windows中打开文件)。

我尝试使用run(`test.txt`),但找不到文件。然后我意识到我需要一个命令在前面,所以我尝试了run(`run test.txt`)。这似乎找到了文件,但是文件在启动时立即崩溃。我应该如何打开该文件?谢谢。

1 个答案:

答案 0 :(得分:0)

虽然您不清楚“打开文件” 的概念,但是我认为您想在外部编辑器中查看文件。这将在Windows上运行:

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Linq;

namespace Tools.Tester
{
    class Stackoverflow
    {
        public static void Question()
        {
            SyntaxTree tree = SyntaxFactory.ParseSyntaxTree(
            @"
            public class Class
            {
                public void Method(){}
            }
            "
            );

            //REPLACE CLASS
            SyntaxNode Class = tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>().First();
            SyntaxNode ClassNew = Class.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia("///<summery>XML</summery>").Add(SyntaxFactory.EndOfLine("\n")));

            /*CLASS SHOULD NOW:
            ///<summery>XML</summery>
            public class Class
            {
                public void Method(){}
            }
            */

            //REPLACE METHOD CHANGE TO CLASS NEW HERE
            SyntaxNode Method = ClassNew.DescendantNodes().OfType<MethodDeclarationSyntax>().First();
            SyntaxNode MethodNew = Method.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia("///<summery>XML</summery>").Add(SyntaxFactory.EndOfLine("\n")));

            /*METHOD SHOULD NOW:
            ///<summery>XML</summery>
            public void Method(){}                
            */

            ClassNew = ClassNew.ReplaceNode(Method, MethodNew);
            /*CLASS SHOULD NOW:
            ///<summery>XML</summery>
            public class Class
            {
                ///<summery>XML</summery>
                public void Method(){}
            }
            */

            //UPDATE TREE
            SyntaxTree treeNew = SyntaxFactory.ParseSyntaxTree(tree.GetRoot().ReplaceNode(Class, ClassNew).GetText());
            string code = treeNew.GetText().ToString();
            Console.WriteLine(code);

            /*RESULT:
            ///<summery>XML</summery>
            public class Class
            {                
                public void Method(){}
            }
            */
        }
    }
}