.bat

@echo off

REM The name of the file that will be created

set filename=electronfileexample.txt

REM the path where the file will be created

set filepath=c:\

REM the content of the file

set content=Hello, this is the content of my file created with batch

REM the full path (path+filename)

set fullpath=%filepath%%filename%

echo Sending a "JSON" String

echo {"filename":"%filename%","content":"%content%","fullpath":"%fullpath%"}

REM Text to send to stdout (data)

REM Note that you can append 2>&1 to the normal stdout

REM echo This text will be sent to my Electron Project

REM or

REM echo This text will be sent to my Electron Project 2>&1

REM Text to send to stderr (error) 1>&2

REM echo This text should ouput an error 1>&2

echo An error message passing by, nothing important :) Just ignore me 1>&2

IF EXIST %filepath%%filename% (

    echo File already exists

    EXIT /B 1

) ELSE (

    @echo Creating file in %fullpath%

    (

      echo %content%

    ) > %filepath%%filename%

)

REM Check if the file was created, if exists send code 2

REM if the file doesn't exist then send code 3 (error while creating)

IF EXIST %filepath%%filename% (

    EXIT /B 2

) ELSE (

    EXIT /B 3

)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • .bat脚本基本命令语法 目录 批处理的常见命令(未列举的命令还比较多,请查阅帮助信息) 1、REM 和 :: 2...
    庆庆庆庆庆阅读 8,213评论 1 19
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,546评论 5 6
  • 上班一个多月来,从来没有这么舒畅地睡到十点。 早上起来,室友都已经去上班了,我眯着眼起来上厕所,厨房外的阳光最先透...
    铛妹阅读 317评论 0 0